class User():
def __init__(self,first_name,last_name,*toppings): # *toppings (带*号表示任意数量的形参)
self.extra_info = [] # 建立空列表,作为容纳可选实参的空间,这里要注意为了能够在整个
self.first_name = first_name # 类的范围里使用该列表,是需要加self的,否则列表就只限于该函数。
self.last_name = last_name
for topping in toppings: #借助for循环,将可选实参的值一个个加入空列表
self.extra_info.append(topping)
def describe_user(self):
print("First_name: " + self.first_name)
print("Last_name: " + self.last_name)
print(str(self.extra_info) + "
")
def greet_user(self):
print("Nice to meet you, "
+ self.last_name + " "
+ self.first_name)
Jerry = User('Huang','Jerry','21','love Eurus Dai')
Jerry.describe_user()
Eurus = User('Dai','Eurus','20','love Jerry Huang')
Eurus.describe_user()