for_python_n_books: else: 那些ptyhon書上沒教事/那些書上沒教的pyhon 12事(123式))
https://medium.com/citycoddee/python%E9%80%B2%E9%9A%8E%E6%8A%80%E5%B7%A7-6-%E8%BF%AD%E4%BB%A3%E9%82%A3%E4%BB%B6%E5%B0%8F%E4%BA%8B-%E6%B7%B1%E5%85%A5%E4%BA%86%E8%A7%A3-iteration-iterable-iterator-iter-getitem-next-fac5b4542cf4
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> h = [1,2,3]
>>> print(dir(h))
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>>> print(hasattr(x,'__iter___'))
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
print(hasattr(x,'__iter___'))
NameError: name 'x' is not defined
>>> print(hasattr(x, '__iter__'))
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
print(hasattr(x, '__iter__'))
NameError: name 'x' is not defined
>>> print(hasattr(h, '__iter__'))
True
>>> print(hasattr(h, '__next__'))
False
>>>
ATTEMPTED
留言
張貼留言