class people: def __init__(self,name,age,sex): self.Name = name self.Age = age self.Sex = sex def speak(self): print ("my name:" + self.Name) zhangsan=people("xiaoai",22,"male") print(zhangsan.Name) print(zhangsan.Age) print(zhangsan.Sex) zhangsan.speak() people.coorporation="huawei" print(people.coorporation)
注解:
- 可以使用类名直接给类添加属性。