"""
类成员:
属性:
数据属性 (保存在类中) 对象 类都可以访问
函数属性
方法:
普通方法(保存在类中) 由对象来调用 self 代指 对象
静态方法 @staticmetic
类方法 cls当前类 @classmetic
当对象中需要保存一些值,执行某些功能时,需要使用对象的值 ----> 普通方法
不需要任何对象中的值 ----> 静态方法
"""
class test(object):
"""aaaaaaaaa""" #doc
a = 1 #静态字段 属于类 类 对象都可以访问
def __init__(self,name,age): #构造方法
self.name = name #字段(普通字段) 只能对象访问
self.age = age
def tt(self): #普通方法
print("my name is %s"%self.name)
p = test("yy",18) #实例化 self就是p
print(p.__dict__) #{'name': 'yy', 'age': 18}
print(p.name) #yy
print(p.a) #1
print(p.__doc__) #aaaaaaaaa
print(p.__module__) #main
p.tt() #my name is yy
class Chinese:
country='China'
def __init__(self,name):
self.name=name
def play_ball(self,ball):
print('%s 正在打 %s' %(self.name))
p1=Chinese('alex')
print(p1.country)
p1.country = "japan"
print('实例的--->',p1.country) #改的是p1
print('类的---->',Chinese.country) #类的没有改变