欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

pythonClass:獲取對(duì)象類型

獲取對(duì)象類型:

金鳳ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!

一、type

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

class Animal(object):
    def __init__(self, name, score):
        self.name = name
        self.score = score
    def run(self):
        print 'Animal is run'

class Dog(Animal):
    def run(self):
        print 'Dog is run'

print type(dog.run)

python Class:獲取對(duì)象類型

print type(Animal)

python Class:獲取對(duì)象類型

import types #導(dǎo)入模塊types
print type('abc')==types.StringType #判斷'abc'是否為字符串類型

python Class:獲取對(duì)象類型

print type(u'abc')==types.UnicodeType

python Class:獲取對(duì)象類型

print type([])==types.ListType

python Class:獲取對(duì)象類型

print type(int)==type(str)==types.TypeType   #所有的類型都是TypeType

python Class:獲取對(duì)象類型

二、isinstance類型

對(duì)于繼承關(guān)系class,用isinstance最為方便。

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

class Animal(object):
    def __init__(self, name, score):
        self.name = name
        self.score = score
    def run(self):
        print 'Animal is run'

class Dog(Animal):
    def run(self):
        print 'Dog is run'

print isinstance(dog, Dog) and isinstance(dog, Animal)

python Class:獲取對(duì)象類型

三、attr類型

  1. getattr()

  • getattr(object, name[, default])?

  • Return the value of the named attribute of object.  name must be a string. If the string is the name of one of the object’s attributes, the result is the value of that attribute.  For example, getattr(x, 'foobar') is equivalent tox.foobar.  If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised.

    對(duì)象的狀態(tài)存在,則返回狀態(tài)值,若不存在,則返回AttributeError:信息

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

class Animal(object):
    def __init__(self, name, score):
        self.name = name
        self.score = score
    def run(self):
        print 'Animal is run'

class Dog(Animal):
    def run(self):
        print 'Dog is run'

dog = Dog('Pity', 98)
dog.run()

python Class:獲取對(duì)象類型

print getattr(dog, 'name')

python Class:獲取對(duì)象類型

print getattr(dog, 'run')

python Class:獲取對(duì)象類型

print getattr(dog, 'd')

python Class:獲取對(duì)象類型

2.hasattr()

  • hasattr(object, name)?

  • The arguments are an object and a string.  The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an exception or not.)

    參數(shù)是對(duì)象和字符串,如果字符串是對(duì)象中的,返回True,否則返回False

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

class Animal(object):
    def __init__(self, name, score):
        self.name = name
        self.score = score
    def run(self):
        print 'Animal is run'

class Dog(Animal):
    def run(self):
        print 'Dog is run'

dog = Dog('Pity', 98)

print hasattr(dog, 'color')

python Class:獲取對(duì)象類型

3.setattr()

  • setattr(object, name, value)?

  • This is the counterpart of getattr().  The arguments are an object, a string and an arbitrary value.  The string may name an existing attribute or a new attribute.  The function assigns the value to the attribute, provided the object allows it.  For example, setattr(x, 'foobar', 123) is equivalent tox.foobar = 123.

    設(shè)置屬性變量

       

      #!/usr/bin/env python3
     # -*- coding: utf-8 -*-

    class Animal(object):
           def __init__(self, name, score):
               self.name = name
               self.score = score
          def run(self):
               print 'Animal is run'

    class Dog(Animal):
         def run(self):
               print 'Dog is run'

   dog = Dog('Pity', 98)

  setattr(dog, 'color', '0xff00ff')
  print dog.color

python Class:獲取對(duì)象類型


當(dāng)前標(biāo)題:pythonClass:獲取對(duì)象類型
地址分享:http://aaarwkj.com/article48/pdhshp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、品牌網(wǎng)站設(shè)計(jì)、App設(shè)計(jì)品牌網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
高颜值美女后入内射视频| 亚洲日本成人一区二区| 欧美日韩精品一区二区视频永久免 | 我想看亚洲一级黄色录像| 久久精品中文字幕有码日本道| 美女诱惑丝袜国产国产av丝袜| 欧美日本在线区一区二| 天天做日日干夜夜操| 久热伊人精品国产中文| 亚洲av乱码毛片在线播放| 可以直接看内射的视频| 成人在线一区二区三区观看| 天天操天天干夜夜射| 91九色中文视频在线观看| 日本中文字幕三级专区| 亚洲成av人在线播放| 日本欧美激情在线观看| 亚洲不卡高清一区二区三区| 国产精品天干天综合网| 国产视频传媒一区二区| 成人午夜激情在线观看| 国产午夜亚洲精品羞羞网站| 久久精品国产亚洲av久一一区| 日本久久久视频在线观看| 韩国黄色理论片一区二区麻豆| 亚洲欧美日韩另类精品一区二区三区| 91麻豆亚洲国产成人久久精品| 男人的天堂av免费看看| 99国产精品热久久婷婷| 尤物资源视频在线观看| 日本一道二区三区我不卡| 超碰欧美黄色免费在线| 国产传媒视频网站在线观看| 麻豆午夜福利在线播放| 日韩av在线观看大全| 内射小美女阴户毛片在线| 亚洲最大黄色免费在线观看| 麻豆一区二区人妻网站| 欧美欧美欧美欧美一二三区| 国产亚洲精品第一最新| 91精品国产综合久久麻豆|