a = [1, 2, 3] b = a b[1] = 4 print(a) print(b) a = [1, 2, 3] b = list(a) b[1] = 4 print(a) print(b) a = [1, [2, 3]] b = list(a) b[1][0] = 4 print(a) print(b) import copy a = [1, [2, 3]] b = copy.copy(a) b[1][0] = 4 print(a) print(b) import copy a = [1, [2, 3]] b = copy.deepcopy(a) b[1][0] = 4 print(a) print(b) import math def sample_function(t): if t < -2: return -2 elif -2 <= t < 0: return t elif t == 0: return 0 else: return t * math.sin(1 / t) sample_function(-5) sample_function(-1) sample_function(0) sample_function(1) %pylab inline t = arange(-5, 5, 0.01) grid() plot(t, list(map(sample_function, t))) x = 1 if True else 2 x x = 1 if False else 2 x a = [[1, 2], [3, 4]] for x in a: for y in x: print(y) for x, y in a: print(x, y) def f(a, b, c): print(a, b, c, sep=", ") f(1, 2, 3) f(1, c=3, b=2) a = [1, 2, 3] f(a) f(*a) a = [2, 3] f(1, *a) d = {'c': 3, 'b': 2, 'a': 1} f(**d) def f(a, b=2, c=3): print(a, b, c, sep=", ") f(1) f(1, 4) f(1, 4, 5) def f(a, b=[]): b.append(a) print(b) f(1) f(2) f(3) def f(*args, **kwargs): print(args, kwargs, sep=", ") f(1, 2, 3, x=4, y=5) name = 'Alice' "Hello, {0}".format(name) "Hello, {}".format(name) name1 = 'Bob' name2 = 'Malory' "Hello, {} and {}".format(name1, name2) "{0}cad{0}".format("abra") "{0.real} + {0.imag}i".format(1 + 2j) "Hello, {name}".format(name="Guido") "Hello, {name[0]} and {name[1]}".format(name=["Jack", "Jill"]) a = 1 b = 2 "{a} + {b} = {}".format(a + b, **locals())