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)

中国
---> 中国-------------------
实例--------》 中国

 点 . 调用只能在类,对象内部调用,没有点只能当成普通,就不会到类实例字典里面去找了










 
posted @ 2018-07-19 07:25  一棵大树一棵小树一棵草  阅读(91)  评论(0编辑  收藏  举报