# Dynamic typing means different number types based on syntax
my_num = 1 # integer
my_num = 1.0 # float (all floats are doubles)
my_num = 1. # also float!
# Most conversion can be done automatically
>>> 1.1 * 2
2.2
# But some can be tricky
>>> 1/2
0
>>> 1./2
0.5>>> "Hello world"[0] # iterable!
"H"
>>> "Hello world"[:5] # iterable!
"Hello"
>>> for letter in "yams": # iterable!
... print letter.upper()
Y
A
M
S
# Most operators work with strings
>>> "wow" * 3
"wowwowwow"
>>> "hello " + "world"
"hello world"
# And unlike JavaScript, things make sense!
>>> "hello" + 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
__init__, __add__, __name__
You shouldn't care what type of object you have
Care if you can do the required action with your object
>>> a = [0,1 2, 3]
>>> print a[0]
0
>>> b = {'a': 0, 'b': 1}
>>> print b['a']
0
# Is the same as
>>> a = [0,1 2, 3]
>>> print list.__getitem__(a, 0)
0
>>> b = {'a': 0, 'b': 1}
>>> print dict._getitem__(b, 'a')
0
# Both lists and dictionaries are supported by this method:
def getit(item, key):
return item[key]thanks yo