What will be the output of the following Python code?
def foo(k): k[0] = 1 q = [0] foo(q) print(q)
[0]
[1]
[1, 0]
[0, 1]
one-star followed by a valid identifier
one underscore followed by a valid identifier
two stars followed by a valid identifier
two underscores followed by a valid identifier
zero
one
zero or more
one or more
def foo(fname, val): print(fname(val)) foo(max, [1, 2, 3]) foo(min, [1, 2, 3])
3 1
1 3
error
none of the mentioned
def foo(): return total + 1 total = 0 print(foo())
0
1
def foo(): total += 1 return total total = 0 print(foo())
def foo(x): x = ['def', 'abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))
True
False
None
Error
def foo(i, x=[]): x.append(i) return x for i in range(3): print(foo(i))
[0] [1] [2]
[0] [0, 1] [0, 1, 2]
[1] [2] [3]
[1] [1, 2] [1, 2, 3]
def foo(k): k = [1] q = [0] foo(q) print(q)
one star followed by a valid identifier
getopt
os
getarg
main
set
list
tuple
string
null
you cannot access it
the program’s name
the first argument
identifier followed by an equal to sign and the default value
identifier followed by the default value within backticks (“)
identifier followed by the default value within square brackets ([])
identifier
def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))
sys.argv
os.argv
argv
def foo(i, x=[]): x.append(x.append(i)) return x for i in range(3): y = foo(i) print(y)
[[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]
[[0], [[0], 1], [[0], [[0], 1], 2]]
[0, None, 1, None, 2, None]
def f1(): x=15 print(x) x=12 f1()
12
15
1512
def f1(): x=100 print(x) x=+1 f1()
100
101
99