7_19 day24 21min 对象与实例属性
# class Chinese:
# country='China'
# def __init__(self,name):
# self.name=name
#
# def play_ball(self,ball):
# print('%s 正在打 %s' %(self.name,ball))
# p1=Chinese('alex')
# print(p1.country)
# p1.country='日本'
# print('类的--->',Chinese.country)
# print('实例的',p1.country)
//China;类的---> China;实例的 日本
country='中国'
class Chinese:
def __init__(self,name):
self.name=name
def play_ball(self,ball):
print('%s 正在打 %s' %(self.name,ball))
p1=Chinese('alex')
print(p1.country)//会报错,只会在类里面找
country='中国-------------------'
class Chinese:
def __init__(self,name):
self.name=name
print('--->',country)
def play_ball(self,ball):
print('%s 正在打 %s' %(self.name,ball))
p1=Chinese('alex')
因为不是 . 引用,所以能找到country,和上面做对比
---> 中国-------------------
country='中国-------------------'
class Chinese:
country='中国'
def __init__(self,name):
self.name=name
print('--->',country)
def play_ball(self,ball):
print('%s 正在打 %s' %(self.name,ball))
print(Chinese.country)
p1=Chinese('alex')
print('实例--------》',p1.country)
中国
---> 中国-------------------
实例--------》 中国
点 . 调用只能在类,对象内部调用,没有点只能当成普通,就不会到类实例字典里面去找了
浙公网安备 33010602011771号