Python dir和vars的区别

dir()和vars()的区别就是

dir()只打印属性(属性,属性......)

而vars()则打印属性与属性的值(属性:属性值......)

ex.

>> a='aaaaaaaaaaaaa'
>> class b:
>>     c = 'cccc'

>> dir()
>>['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'a', 'b']    

>> vars()
>> {'a': 'aaaaaaaaaaaaa', 'b': , '__builtins__': , '__file__': 'C:\\Users\\CS11\\Desktop\\test.py', '__package__': None, '__name__': '__main__', '__doc__': None} 
>> dir(b)  
>>['__doc__', '__module__', 'c']
   
>> vars(b)
>>{'__module__': '__main__', 'c': 'cccc', '__doc__': None}
posted @ 2018-11-11 02:42  暮晨  阅读(751)  评论(0编辑  收藏  举报

Aaron Swartz was and will always be a hero