六十六、repr方法
1、定义:
repr(...) repr(object) -> string Return the canonical string representation of the object. For most object types, eval(repr(object)) == object.
2、解释:返回一个对象的规范的string表现形式,对于大多数对象类型满足以下等式:eval(repr(object)) == object.
3、举例:
>>> repr(123) '123' >>> repr("abc") "'abc'" >>> repr(dict(a=12, b="aaa", c=dict(d='dd'))) "{'a': 12, 'c': {'d': 'dd'}, 'b': 'aaa'}" >>> _dict = repr(dict(a=12, b="aaa", c=dict(d='dd'))) >>> eval(_dict) {'a': 12, 'c': {'d': 'dd'}, 'b': 'aaa'}
六十七、reversed类
1、定义:
class reversed(object) | reversed(sequence) -> reverse iterator over values of the sequence | | Return a reverse iterator
2、解释:返回一个序列的反向迭代器
3、举例:
>>> a = reversed('abcd') >>> a.next() 'd' >>> b = reversed(range(5)) >>> b.next() 4
Copyright © 2021.aoyanming个人博客站
发表评论