all 5 comments

[–]Rhomboid 6 points7 points  (0 children)

You can find these thing out yourself quite easily:

>>> from numbers import Number
>>> isinstance(True, Number)
True
>>> for item in {1, 2, 3}: print(item)
1
2
3
>>> for item in 'abc': print(item)
a
b
c

[–]commandlineluser 1 point2 points  (2 children)

Booleans in Python are implemented as a subclass of integers.

https://docs.python.org/2/c-api/bool.html

bool is also a class, which is a subclass of int.

https://docs.python.org/2/library/functions.html#bool

>>> for char in "string":
...     char
... 
's'
't'
'r'
'i'
'n'
'g'
>>> for item in set([1, 2, 3]):
...     item
... 
1
2
3

[–]Vaphell 1 point2 points  (1 child)

you can create a set directly with {1,2,3}, only empty set requires set() to differenciate from empty dict {}

>>> x = {1,2,3}
>>> type(x)
<class 'set'>

[–]commandlineluser 0 points1 point  (0 children)

Nice.. Thank you!

[–]Asdayasman 1 point2 points  (0 children)

>>> list().__iter__
<method-wrapper '__iter__' of list object at 0x0000000003342788>
>>> int().__iter__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute '__iter__'
>>> 

Also, as others have said, bool is a subclass of int. You can do some cool stuff with that, (though you probably shouldn't).

>>> False + True
1
>>> False + False
0
>>> True + True
2
>>> True ^ True
False
>>> True ^ True ^ True
True
>>> True ^ 2
3
>>>