新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python中類對象及類屬性的介紹
說明

1、類對象:類的定義就生成了一個類對象。
2、類的屬性:類定義中的變量和類中定義的方法都是類的屬性。
Myclass 中,x、foo都是類的屬性,__doc__也是類的屬性
foo方法是類的屬性,類實例化之后就可以調(diào)用
foo是方法對象method,不是普通的函數(shù)對象function了,它一般要求至少有一個參數(shù),第一個參數(shù)可以是self(self只是習(xí)慣用標(biāo)識符,可以換名字),這個參數(shù)位置就留給了self。
實例
class Myclass:
"""My class """
x = "abc"
def foo(self):
return "This My class {} ".format(id(self))
print(Myclass.x) #abc
print(Myclass.foo) #
print(Myclass.__doc__) #My class
以上就是python中類對象及類屬性的介紹,希望對大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)Python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
文章題目:創(chuàng)新互聯(lián)Python教程:python中類對象及類屬性的介紹
鏈接地址:http://fisionsoft.com.cn/article/cddoshe.html


咨詢
建站咨詢
