1 + 3 3. * 2. complex(2.,4.) - complex(1.,6.) 3 * 9.2 # int * float = float 2. * complex(-1.,3.) # float * complex = complex 8 * complex(-3.3,1) # int * comples = comples 3 / 2 3 / float(2) 3 / 2. 3/2 3//2 #from __future__ import division (this does not work in the body of a script, it needs to be at the top!) l = [4, 5.5, "spam"] l[0] l[1] l[2] t = (4, 5.5, "spam") t[0] t[1] t[2] l = [1, 2, 3, 4, 5] l[2:4] l[3:] l[:3] l[::2] l[-1] l[-2:] r = l[::-1] r l[0] = 28 l l[2:4] = [3, 8] l l = [3, 2, 'hello'] l l[1], l[2] l = [1, 2, 3, 4, 5] l.append(6) r + l r.sort() l = [1, 2, 3] l.append('egg') # For a full list of methods, type l. then press TAB! l.insert(3, 'spam') set([1, 2, 3, 2, 'spam', 'egg', 'spam']) set([1,2,3]) - set([3,4]) set([1,2,3]) & set([3,4]) set([1,2,3]) | set([3,4]) 'a' in set(['a', 'b', 'c', 'd', 'e', 'f']) s = "Spam egg spam spam" "I'm" '"hello"' 'I\'m' "\"hello\"" s = "hello" s[0] s[1] s = "hello, world!" s[5] = 'r' "hello," + " " + "world!" s = "Spam egg spam spam" s.upper() # An uppercase version of the string s.index('egg') # An integer giving the position of the sub-string s.split() # A list of strings print('{:8.3f}'.format(3.14159265)) print('{:.10f}'.format(3.14159265)) print('{:.6e}'.format(3.14159265)) print('{:04d}'.format(3)) print('{:g}'.format(3.14159265)) print('{:g}'.format(0)) print('{:g}'.format(10000000000000000000000)) d = {'name':'m31', 'ra':10.68, 'dec':41.27} d['name']