# 類與對象
# 對象:有屬性(特征)和函數/方法(行為),是類的實例
# 類:關鍵字是class,是創建對象的模板
class Human:
# 構造函數,初始化函數
def __init__(self, breed, sex, height = '170'):#默認值
# 定義三個屬性
self.breed = breed
self.sex = sex
self.height = height
# def __init__(self):
# # 定義三個屬性
# self.breed = None
# self.sex = None
# self.height = None
# 定義的3個函數
def study(self):
print("學習")
def eat(self):
print("吃飯")
def sleep(self):
print("睡覺")
print("一個%s血型,性別:%s,身高:%s" % (self.breed, self.sex, self.height))
# 類和對象的關系:類是創建對象的模板,對象是累的實例
human = Human('A', '女')
# human.breed = 'A'
# human.sex = '女'
# human.height = '170'
human.eat()
human.sleep()
human.study()
# 判斷函數type()
print(type(human)) # Human類型
print(type(human) == Human)
# isinstance判斷是否是實例?
print(isinstance(human, Human)) # 參數1是對象,參數2是判斷的類