企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[链接](https://www.runoob.com/python3/python3-class.html) `__weight ` ---定义私有属性,私有属性在类外部无法直接进行访问 `def __init__(self,n,a,w):`----定义构造方法,,,self代表类的实例,而非类 `类定义了 __init__() 方法,类的实例化操作会自动调用 __init__() 方法` ``` #!/usr/bin/python3 #类定义 class people: #定义基本属性 name = '' age = 0 #定义私有属性,私有属性在类外部无法直接进行访问 __weight = 0 #定义构造方法 def __init__(self,n,a,w): self.name = n self.age = a self.__weight = w def speak(self): print("%s 说: 我 %d 岁。" %(self.name,self.age)) # 实例化类 p = people('runoob',10,30) p.speak() ```