python之函数用法vars()
生活随笔
收集整理的這篇文章主要介紹了
python之函数用法vars()
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#python之函數(shù)用法vars()
#vars()
#說明:返回對(duì)象object的屬性和屬性值的字典對(duì)象
'''
vars(...)
vars([object]) -> dictionary
dictionary:字典對(duì)象
Without arguments, equivalent to locals().
With an argument, equivalent to object.__dict__.
'''
class My():
'Test'
def __init__(self,name):
self.name=name
def test(self):
print self.name
vars(My)#返回一個(gè)字典對(duì)象,他的功能其實(shí)和 My.__dict__ 很像
for key,value in vars(My).items():
print key,':',value
'''
test : <function test at 0x02112C70>----test函數(shù)
__module__ : __main__
__doc__ : Test
__init__ : <function __init__ at 0x01E42B70>----構(gòu)造函數(shù)
'''
總結(jié)
以上是生活随笔為你收集整理的python之函数用法vars()的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个初学者的SAP Cloud Plat
- 下一篇: 亿图eddx与visio转换