三十四、hasattr方法
1、定义:
hasattr(...)
hasattr(object, name) -> bool
Return whether the object has an attribute with the given name.
(This is done by calling getattr(object, name) and catching exceptions.)2、解释:返回一个bool类型,用于判断一个对象是否具有某个属性。具体运行方式:以带处理异常的方式调用getattr方法。与delattr、getattr、setattr属一个系列。
3、举例:
>>> import datetime >>> hasattr(datetime,'time') True >>> hasattr(datetime,'a') False
三十五、hash方法
1、定义:
hash(...)
hash(object) -> integer
Return a hash value for the object. Two objects with the same value have
the same hash value. The reverse is not necessarily true, but likely.2、解释:返回一个对象的哈希值。若两个对象值相同则返回同一个哈希值,但是如果哈希值相同对象的值是不一定相同的,但有可能相同。
3、举例:
>>> import datetime
>>> hash(datetime)
564273
>>> hash(datetime.datetime)
31614620
>>> hash(datetime.time)
31614494
>>> hash('1234')
1723328704
>>> hash('1234')
1723328704
>>> hash(datetime.time)
31614494三十六、help方法
此方法前面已讲解,顾名思义,用于查看使用帮助的。使用方法:help(需要查看帮助的对象)
Copyright © 2021.aoyanming个人博客站
发表评论