一、初识对象
1.
class Student:
name=None
def a(self,msg):
print(f"大家好呀,我是{self.name},{msg}")
stu=Student()
stu.name="周杰伦"
stu.a("hhhhhhh")
![](https://i-blog.csdnimg.cn/blog_migrate/a4c1d9636c37084be1c52c23e10f536d.png)
二、成员方法
class Student:
name=None
age=None
tel=None
def __init__(self,name,age,tel):
self.name=name
self.age=age
self.tel=tel
print("student类创建了")
stu=Student("cc",12,123456)
三、其它内置方法
class Student:
def __init__(self,name,age):
self.name=name
self.age=age
def __str__(self):
return f"Student类对象,name:{self.name},age:{self.age}"
def __lt__(self, other):
return self.age<other.age
def __le__(self, other):
return self.age<=other.age
def __eq__(self, other):
return self.age==other.age
# stu=Student("cc",23)
# print(stu)
stu1=Student("这种",99)
stu2=Student("钉钉",69)
print(stu1<stu2)
print(stu1<=stu2)
print(stu1==stu2)
![](https://i-blog.csdnimg.cn/blog_migrate/17b8e668a90c470c056111bed15eb948.png)
四、封装
class Phone:
__current_voltage=3
def __keep_single_core(self):
print("让cpu以单核模式运行")
def call_by_