标签:传参数 object 执行 构造 面向对象 gif 基本 color 删除
1 class Person(object): 2 def __init__(self, name, age): 3 self.name = name 4 self.age = age 5 6 7 p = Person("Alex", 22) 8 print(p.name, p.age)
1 class Person(object): 2 def __init__(self, name, age): 3 self.name = name 4 self.age = age 5 6 7 p = Person("Alex", 22) 8 print(p.name, p.age)
1 # p = Person("Alex", 22) 2 # print(p.name, p.age)
1 #加上句print(Person) 2 print(Person) 3 #执行结果 4 <class ‘__main__.Person‘>
1 #加上句print(Person) 2 print(Person) 3 #执行结果 4 <class ‘__main__.Person‘>
1 class Person(object): 2 def __init__(self, name, age): 3 self.name = name 4 self.age = age 5 6 def talk(self): 7 print("Hello, my name is %s, I‘m %s years old!" % (self.name, self.age)) 8 9 10 p = Person("Alex", 22)# print(p.name, p.age) 11 p.talk() #注意这里调用并未传递参数
1 class Person(object): 2 def __init__(self, name, age): 3 self.name = name 4 self.age = age 5 6 def talk(self): 7 print("Hello, my name is %s, I‘m %s years old!" % (self.name, self.age)) 8 9 10 p = Person("Alex", 22)# print(p.name, p.age) 11 p.talk() #注意这里调用并未传递参数
1 # 执行输出 2 Hello, my name is Alex, I‘m 22 years old!
1 class Person(object): 2 def __init__(self, name, age): 3 self.name = name 4 self.age = age 5 6 def talk(self): 7 print("Hello, my name is %s, I‘m %s years old!" % (self.name, self.age)) 8 9 def __del__(self): 10 print("running del method, this person must be died.") 11 12 13 p = Person("Alex", 22) 14 p.talk() 15 16 del p 17 18 print(‘--end program--‘)
1 class Person(object): 2 def __init__(self, name, age): 3 self.name = name 4 self.age = age 5 6 def talk(self): 7 print("Hello, my name is %s, I‘m %s years old!" % (self.name, self.age)) 8 9 def __del__(self): 10 print("running del method, this person must be died.") 11 12 13 p = Person("Alex", 22) 14 p.talk() 15 16 del p 17 18 print(‘--end program--‘)
标签:传参数 object 执行 构造 面向对象 gif 基本 color 删除
原文地址:https://www.cnblogs.com/oceanicstar/p/8846462.html