PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Pure vs. Impure functions
# -------------------------
# PURE: The only result of calling a pure function is the return value; Pure functions can be run multiple times and will give you the same result.
def new_list(list, arg):
return list + arg
words = ["Hello"]
greetings = new_list(words, ["Bonjour", "Hola"])
print(words)
print(greetings)
print("")
# IMPURE: Impure functions change the state of an outside variable; doesn't have a return statement
def add_to_list(arg):
groceries.append(arg)
groceries = ["spam"]
add_to_list("eggs")
print(groceries)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run