Python

Python

Argument Passing has 19 Questions
What is the type of each element in sys.argv?

set
list
tuple
string
What is the output of the following code?
def foo(k):
    k[0] = 1
q = [0]
foo(q)
print(q)

[0]
[1]
[1, 0]
[0, 1]
What is the length of sys.argv?

number of arguments
number of arguments + 1
number of arguments ? 1
none of the mentioned
How many keyword arguments can be passed to a function in a single function call?

zero
one
zero or more
one or more
What is the output of the following code?
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
What is the output of the following code?
def foo():
    return total + 1
total = 0
print(foo())

0
1
error
none of the mentioned
What is the output of the following code?
def foo():
    total += 1
    return total
total = 0
print(foo())

0
1
error
none of the mentioned
What is the output of the following code?
def foo(x):
    x = ['def', 'abc']
    return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))

True
False
None
error
What is the output of the following code?
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]
What is the output of the following code?
def foo(k):
    k = [1]
q = [0]
foo(q)
print(q)

[0]
[1]
[1, 0]
[0, 1]
How are variable length arguments specified in the function heading?

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
Which module in the python standard library parses options received from the command line?

getopt
os
getarg
main
What is the type of sys.argv?

set
list
tuple
string
What is the value stored in sys.argv[0]?

null
you cannot access it
the program's name
the first argument
How are default arguments specified in the function heading?

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
How are required arguments specified in the function heading?

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
What is the output of the following code?
def foo(x):
    x[0] = ['def']
    x[1] = ['abc']
    return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))

True
False
None
error
Where are the arguments recived from the command line stored?

sys.argv
os.argv
argv
none of the mentioned
What is the output of the following?
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]
[[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]