Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. # many types in list >>> lst = [1,2,3.11, "python"] # random access to the i'th element >>> lst[0] 1 >>> lst[3] 'python' #out of range >>> lst[4] Traceback (most recent call last): File "", line 1, in lst[4] IndexError: list index out of range # reverse indices >>> lst[-1] 'python' >>> lst[-2] 3.11 # slicing >>> lst[0:2] [1, 2] >>> lst[0:3] [1, 2, 3.11] # nested lists >>> "python"[2] 't' >>> lst[3][2] 't' >>> lst = lst+[[3]] >>> lst [1, 2, 3.11, 'python', [3]] >>> lst[4][0] 3 >>> lst[4] [3] # extend, insert and append (in-place functions). # lst.insert(len(lst), x) is equivalent to lst.append(x). >>> lst.insert(1,1.5) >>> lst [1, 1.5, 2, 3.11, 'python', [3]] >>> lst.append(3) >>> lst [1, 1.5, 2, 3.11, 'python', [3], 3] >>> lst.append([7]) >>> lst [1, 1.5, 2, 3.11, 'python', [3], 3, [7]] >>> lst.extend([7]) >>> lst [1, 1.5, 2, 3.11, 'python', [3], 3, [7], 7] >>> lst = lst + [7] >>> lst [1, 1.5, 2, 3.11, 'python', [3], 3, [7], 7, 7] >>> lst.extend(7) Traceback (most recent call last): File "", line 1, in lst.extend(7) TypeError: 'int' object is not iterable >>> # sum, len, sort and sorted >>> lst = [1,1.1, 2,3] >>> sum(lst) 7.1 >>> len(lst) 4 >>> lst = [1,1.1, 2,3, 12,7,9,0.5] >>> lst2 = sorted(lst) >>> lst2 [0.5, 1, 1.1, 2, 3, 7, 9, 12] >>> lst = ["d", "a", "c", "b"] >>> lst2 = sorted(lst) >>> lst2 ['a', 'b', 'c', 'd'] >>> lst = ["d", "a", "c", "b", 1] >>> lst2 = sorted(lst) Traceback (most recent call last): File "", line 1, in lst2 = sorted(lst) TypeError: unorderable types: int() < str() >>> lst2 = sorted(lst, reverse = True) >>> lst2 ['d', 'c', 'b', 'a'] >>> lst ['d', 'a', 'c', 'b'] >>> lst.sort() >>> lst ['a', 'b', 'c', 'd'] >>> sorted(lst, reverse = True) ['d', 'c', 'b', 'a'] >>> lst ['a', 'b', 'c', 'd'] >>> lst = [lst] >>> lst [['a', 'b', 'c', 'd']] >>> # initializing list with default values in cells >>> [0]*3 [0, 0, 0] >>> lst = [-1]*10 >>> lst [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] # list comprehension >>> lst = [1,2,3,4] >>> lst2 = [2*x for x in l if x < 4] Traceback (most recent call last): File "", line 1, in lst2 = [2*x for x in l if x < 4] NameError: name 'l' is not defined >>> lst2 = [2*x for x in lst if x < 4] >>> lst2 [2, 4, 6] >>> lst2 = [True for x in lst if x < 4] >>> lst2 [True, True, True] >>> lst = [1,2,3,4,1] >>> lst2 = [2*x for x in lst if x < 4] >>> lst2 [2, 4, 6, 2] >>> lst.sort() >>> lst [1, 1, 2, 3, 4] >>> sorted(lst) [1, 1, 2, 3, 4] >>> =================== RESTART: C:/Users/user/Desktop/max2.py =================== # re-use of functions >>> max2(10,5) 10 >>> max2(-1,5) 5 >>> max2(5,5) 5 >>> max2(5.1,5) 5.1 # short circuit evaluation >>> 3//0 Traceback (most recent call last): File "", line 1, in 3//0 ZeroDivisionError: integer division or modulo by zero >>> 3//0 and False Traceback (most recent call last): File "", line 1, in 3//0 and False ZeroDivisionError: integer division or modulo by zero >>> False and 3//0 False >>> True or 3//0 True >>>