1. 面向对象编程(OOP)
代码示例1:类的定义与使用
class Student:
name = None
age = None
tel = None
Student1 = Student()
Student1.name = "jkh"
Student1.age = "htfrv"
代码示例2:构造方法 __init__
和实例方法
class student:
def __init__(self, name, age):
self.name = name
self.age = age
stu1 = student("jyfg", 11)
stu2 = student("jkgh", 23)
代码示例4:类的继承与方法重写
class Phone:
IMET = phone
produser = None
def call_by_5g(self):
print("jkgh")
class MyPhone(Phone):
produser = "jhg" # 重写父类属性
def call_by_5g(self): #重写父类方法
print("kjghkj")
代码示例5:多继承
class NFcReader:
nfc_type = "jhg"
produser = "iugh"
def read_card(self):
print("juh")
def read_write(self):
print("juh")
class Remotecontro1:
rc_type = "jhyfyt"
def control(self):
print("jyhfgu")
class MyPhone(Phone, NFcReader, Remotecontro1):
pass
代码示例6:多态
def make_noise(animal: Anim