|
发表于 2019-11-17 13:27:26
|
显示全部楼层
还有 count 和 index 两个方法
- >>> dir(range(1, 10, 2))
- ['__bool__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index', 'start', 'step', 'stop']
- >>> a = range(1, 10, 2)
- >>> a.count
- <built-in method count of range object at 0x033F0368>
- >>> a.count(2)
- 0
- >>> a.count(3)
- 1
- >>> a.index(3)
- 1
复制代码 |
|