#### Python Assignment in Functions Flashcards

card 1 of 10

def Raz(x):
a = 3
return x+a
>>> a = 0
>>> Raz(7)
>>> a

function namespace is isolated

10
0

card 2 of 10

def Mor(x):
a = 9
return x+a
def Raz(x):
a = 3
return x+a
>>> a = 0
>>> Raz(Mor(7))
>>> a

function namespace is isolated

19
0

card 3 of 10

def Mor(x):
return x+a
def Raz(x):
a = 3
return x+a
>>> a = 0
>>> Raz(Mor(7))
>>> Mor(Raz(7))
>>> a

function namespace is isolated

10
10
0

card 4 of 10

def Mor(x):
return x+a
def Raz(x):
a = 3
return Mor(x)
>>> a = 0
>>> Raz(7)
>>> a

function namespace is isolated

7
0

card 5 of 10

def double(x):
x = 2*x
>>> x = 3
>>> double(x)
>>> x

function namespace is isolated

3

card 6 of 10

def double(x,y):
x = 2*x
y = 2*y
>>> x,y = 3,5
>>> double(x,y)
>>> x,y

function namespace is isolated

(3,5)

card 7 of 10

def repFirst(X):
X[0] = True
>>> myseq = [5,2,1]
>>> repFirst(myseq)
>>> myseq

functions can modify list arguments

[True,2,1]

card 8 of 10

def repFirst(X):
X[0] = True
>>> mydc = {90:"ninety", 2:"car"}
>>> repFirst(mydc)
>>> mydc

functions can modify dictionary arguments

{0:True, 90:'ninety', 2:'car'}

card 9 of 10

def extend(X):
X = X + [100]
>>> myseq = [5,2,1]
>>> extend(myseq)
>>> myseq

functions can modify list arguments, but not by assignment to entire list

[5,2,1]

card 10 of 10

def truncate(X):
X[-2:-1] = [ ]
>>> myseq = [5,2,1]
>>> truncate(myseq)
>>> myseq

functions can modify list arguments by index or slice assignment

[5,1]

#### End of Problem Set

(use browser reload to restart this problem set)