# sideEffects.py # CS 251 Lesson 6 # Studies in the side effects of different Python statements # First we'll play with some integers a = 10 b = a b = 20 print("### TEST 1 ###") print(a, b) # Now we'll look at function scope def f(x): a = 4 x += 1 print("In f: ", a, x) print("\n### TEST 2 ###") print("Before f:", a, b) f(b) print("After f: ", a, b) # How could we change a? def g(): global a a += 1 print("In g: a=", a) print("\n### TEST 3 ###") print("Before g:", a, b) g() print("After g: ", a, b) # Okay, now what if we look at lists, not just ints? def h(vals): if len(vals) > 0: vals[0] = "apple" print("In h: ", vals) print("\n### TEST 4 ###") lst = ['a', 'b', 'c', 'd'] print("Before h:", lst) h(lst) print("After h: ", lst)