#在类名中传入参数:构造方法 class Person: name = "xxx" def __init__(self,name): self.name=name zhangsan = Person("zhangsan") print(zhangsan.name) lisi = Person("lisi") print(lisi.name) ############################### class CLanguage: '''这是一个学习Python定义的一个类''' def __init__(self,name,add): print(name,"的网址为:",add) #传递参数给构造函数 CLanguage("C语言中文网","http://c.biancheng.net") CLanguage("C语言","http://")
标签:__,name,Python,self,print,构造函数 From: https://www.cnblogs.com/shan-gui-yao/p/17465265.html