2 + 3 2 - 3 2 * 3 2**3 2 / 3 5 // 3 5 % 3 2 / 3. # float int(2 / 3.) int('1') float(1) float('1.3') long(1.300) complex(2, 3) complex('2+3j') one = 1 one two, three, four = 2, 3, 4 print four, three a = b = c = 1 a b c #working only with python3 a, *b, c = [1, 2, 3, 4, 5, 6] a == 1 b == [2, 3, 4, 5] c == 6 complex0 = -3j # complex complex0.imag complex0.real complex0**2 abs(-1.45) pow(2, 3) import math round(math.pi, ndigits=3) x = 2 # assign a variable y = 3 x * y math.sin(math.pi/2.) # use functions and variables from the math library # if you import the math library with: # from math import * # become: sin(pi/2.) true = True false = False none = None one = 1 zero = 0 a = 'a' true is True # use "is" to check that is the same object false is not True true == True one > zero # >/>=/ zero and zero > -one one < zero or zero < -one string ='qwertyuiopasdfghjklzxcvbnm' string[0] # get the first element of the string len(string) # get the lenght of the string string[25] # get the last element of the string string[-1] # get the last string[0:6] # start=0, stop=6 string[::3] # step=3 unicodestr = u'àèéìçòù' unicodestr[:3] print unicodestr[:3] numb = '0123-5678' numb[4] numb[4] = 4 'a'+'b'+'c' 'abc'-'c' 'a'*4 multirow = 'Things that I like in python:\n - syntax;\n - power.\n' print multirow multirow = """Things that I like in python: - syntax; - power. """ print multirow findstr = "find something inside" findstr.find('s') findstr[9:] findstr[9:].find('s') print(multirow.replace('syntax', "it's nice")) stripstr = ' some spaces ' stripstr.strip() # try the effect of: lstrip, rstrip splitstr = "split a long phrase, with a lot of words!" splitstr.split() # specify with character should be use to split the string, the defaul is ' ' character = 'A strAngE strIng' character.lower() numbers = '1234' numbers.isdigit() 'python is %s!!!' % 'beautiful' import math 'number int: %05d, float: %f' % (15, math.pi) 'number int: %d, float: %05.2f' % (15, math.pi*100) 'list: %r' % [1,2,3,4] 'SELECT {cols} FROM {table}'.format(cols='cat, name', table='streets') 'SELECT {} FROM {}'.format('cat, name','streets') integer = -12345 double = 3.141592653589793 word = 'python' Get the following strings [3 minutes]: "Still missing: -12345 €" "the pigreco value is around: 3.14159" " python " list_one = ["a", "b", "c", [1,2,3], "d"] list_one list_one[1] list_one[0] list_one[-2] list_one[1:4] list_one[::2] list_one[::-1] list_one.append('a') list_one.count('a') len(list_one) list_one.pop(-1) list_one.sort() list_one list_one.index('b') list_one.extend(['e','f','g','h']) list_one list_one[0][0:0]=[0] list_one list_one.insert(1, [4,5,6]) list_one list_one[-3:]=[] list_one list_one.remove('e') list_one 'a' in list_one tuple_one = (1,2,3,':-)') tuple_one.index(2) tuple_one.count(':-)') 2 in tuple_one tuple_one[0] tuple_one[0] = 10 gis = set(['arcgis', 'mapinfo', 'qgis', 'grass', 'udig']) opensource = set(['qgis', 'grass', 'udig']) usingpython = set(['qgis', 'grass', 'arcgis']) gis - opensource opensource & usingpython # and opensource ^ usingpython # or contact = {'pietro': 333123808, 'jonh': 123123123} contact['pietro'] contact['pietro'] = {'cell': 333123808, 'tel': 04545454} contact['pietro']['cell'] contact.keys() type(contact) type(1) isinstance(contact, dict)