AIR

源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 20:39:19 2020

@author: 不败顽童
"""

class Cat:
def __init__(self,name,color):
# print("cat正在实例化")
self.cat_name = name
self.cat_color = color
self.cat_age = 3
# self.eat() #eat方法想在初始化,实例化的时候调用

def eat(self): # 实例方法 self就是指最终的实例
print("我的{}在吃肉...,他的毛是{}".format(self.cat_name,self.cat_color))
c = self.drink("牛奶")

def drink(self,drinks):
print("我的{}岁的{}在喝{}...".format(self.cat_age,self.cat_name,drinks))
alive = True
return alive

if __name__ == "__main__":
my_cat = Cat("大黄","黄色") # 实例化
print(my_cat.cat_name,my_cat.cat_age)
a = my_cat.eat()
print("a is",a)
is_alive = my_cat.drink("果粒橙")
if is_alive:
print("我的猫还活着")
else:
print("我的猫不活了")

---

cat


 Comments


Blog content follows the Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) License

Use Material X as theme , total visits times .
载入天数...载入时分秒...