a = 10 print a b, c = 3.1, 4 print b, c b, c = c, b print b, c print type(a), type(b), type(c) print 2 ** 300 print type(2 ** 100) a = 2 print a ** 3 / 4 print a ** 3.0 / 4 print a ** 3 / 4.0 print int() print float() print float(3) print int(12.7) print 'Hello world!' print 'Hello world!' == "Hello world!" a = None print a print [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] print range(10) a = [123, 12.0, None, [1, [], []], 'qwerty'] print a[0], a[2] print [[0, 1, 0], [1, 2, 1], [0, 1, 0]][1][1] a = range(10) print a print a[0:5] # elements from 0 to 4 print a[:5] # elements from begin to 4 print a[:] # elements from begin to end print a[2:8:3] # every third element from 2 to 7 print a[-1] # last element print a[::-1] # reverse list a = range(10, 0, -1) print a b = sorted(a) print a, b b.sort(reverse=True) print a, b name = 'Kolya' if name == 'Petya': print 'Romov', name elif name == 'Sasha': print 'Fonarev', name elif name == 'Vasya': print 'Pupkin', name else: print 'Unknown man' data = [19, 2, 4, 6, 7, 3] element_to_find = 10 i = 0 while i < len(data): if data[i] == element_to_find: print "Found!" break i += 1 else: print "Not found!" data = [19, 2, 4, 6, 7, 3] element_to_find = 10 for i in range(len(data)): if data[i] == element_to_find: print "Found!" break else: print "Not found!" data = [19, 2, 4, 6, 7, 3] element_to_find = 10 for element in data: if element == element_to_find: print "Found!" break else: print "Not found!" data = [19, 2, 4, 6, 7, 3] element_to_find = 10 if element_to_find in data: print "Found!" else: print "Not found!" s = 'Machine leerning is cool' s[10] = 'a' s = 'Machine leerning is cool' s = s[:10] + 'a' + s[11:] print s s = 'Machine learning is cool' splitted = s.split(' ') print splitted print '_'.join(splitted) first = ('Masha', 24) first[0] = 'Nastya' first = ('Masha', 24) second = ('Vasya', 30) third = ('Kolya', 20) data = [first, second, third] print data for name, age in data: print name + ' is ' + str(age) + ' years old' print hash(1543) print hash(-15.43) print hash('Kolya') print hash(('Masha', 24)) hash(['Masha', 24]) print {1, 2, 2, 1, 3} print {1, 2, 3, [5, 6]} print sorted(list(set([1, 2, 2, 2, 1, 4, 6, 4]))) print sorted(list(set(range(10)) & set(range(7, 20, 2)))) a = {None: 10, 'Masha': [1, 2, 3], (-1, 1): 0} a['Masha'][1] = 10 print a print {} == set() print {} == dict() import math data = [round(math.sin(i) * 2) for i in range(100)] counter = dict() for element in data: if not element in counter: counter[element] = 1 else: counter[element] += 1 print counter print counter.keys() print counter.values() print counter.items() print [i ** 2 for i in range(20)] print [[] for i in range(3)] print [s + ' is cool' for s in ['Yandex', 'Google', 'Yahoo'] if s[0] == 'Y'] from sys import stdin from sys import stdout for line in stdin: line = line.strip() print >> stdout, line + '!' in_file = open('in_file.txt') out_file = open('out_file.txt', 'w') title = in_file.readline() for line in in_file: cells = line.split(',') print >> out_file, '\t'.join([cells[1], cells[3]]) a = range(5) b = a b[3] = 100 print a, b b = range(10) print a, b def get_degrees(n): return n ** 2, n ** 3 print get_degrees(12) print (lambda n: (n ** 2, n ** 3))(12) def change_list(a, flag=True): if flag: a[0] = 'qwerty' return a = [15, 43] x = [1, 2, 3, 4] y = [1, 2, 3, 4] change_list(x) change_list(y, False) print x, y def my_func(param1, param2='ML', param3=10): print param1, param2, param3 my_func(param2='Data Mining', param1=[0, 0]) class MyClass: def __init__(self, param): self.field = param def get_squared_param(self): return self.field ** 2 a = MyClass(10) print a print a.field print a.get_squared_param()