python 类的创建和使用
原文:https://www.runoob.com/python3/python3-class.html
原文:https://www.cnblogs.com/danhuai/p/11731319.html
class MyClass: """一个简单的类实例""" i = 12345 def f(self): return ‘hello world‘ # 实例化类 x = MyClass() # 访问类的属性和方法 print("MyClass 类的属性 i 为:", x.i) print("MyClass 类的方法 f 输出为:", x.f())
class TestDate: a = 1 # "__init__"为类的构造函数 def __init__(self): self.a = 666 pass def a_1(self): print("a_1") self.a_2() def a_2(self): print(self.a) print("a_2") if __name__ == "__main__": # 实例化类的时候 需要加"()",如TestDate(),若只写成TestDate 则类内部的方法无法相互调用 td = TestDate() td.a_1()
相关推荐
zhuquan0 2020-05-25
bcbeer 2020-05-02
FlySky 2020-11-02
逍遥友 2020-10-26
taiyangshenniao 2020-10-05
flycony 2020-09-23
jacktangj 2020-09-18
YENCSDN 2020-09-15
lsjweiyi 2020-09-14
digwtx 2020-09-14
拾毅者 2020-09-14
zlxcsdn 2020-09-13
weiiron 2020-08-17
amazingbo 2020-08-16
郗瑞强 2020-08-16
lispython 2020-08-16
fengling 2020-08-15
xiesheng 2020-08-02