Python Argument Parsing: MCQs on Argument Parsing

Python Argument Parsing. Multiple Choice Questions on Argument Passing in Python Programming Language.

 

Python Argument Parsing

 

 

What will be the output of the following Python code ??

def foo(i, x=[]):
x.append(i)
return x
for i in range(3):
print(foo(i))

a) [0] [1] [2]
b) [0] [0, 1] [0, 1, 2]
c) [1] [2] [3]
d) [1] [1, 2] [1, 2, 3]

 

What will be the output of the following Python code ??

def foo(i, x=[]):
x.append(x.append(i))
return x
for i in range(3):
y = foo(i)
print(y)

a) [[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]
b) [[0], [[0], 1], [[0], [[0], 1], 2]]
c) [0, None, 1, None, 2, None]
d) [[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]

 

What will be the output of the following code ??

def foo(x):
x = [‘def’, ‘abc’]
return id(x)
q = [‘abc’, ‘def’]
print(id(q) == foo(q))

a) True
b) False
c) None
d) Error

 

Where are the arguments received from the command line stored ??

a) sys.argv
b) os.argv
c) argv
d) none of the mentioned

 

Python Argument Parsing

 

What will be the output of the following Python code ??

def foo():
total += 1
return total
total = 0
print(foo())

a) 0
b) 1
c) error
d) none of the mentioned

 

What will be the output of the following Python code ??

def foo(x):
x[0] = [‘def’]
x[1] = [‘abc’]
return id(x)
q = [‘abc’, ‘def’]
print(id(q) == foo(q))

a) True
b) False
c) None
d) Error

 

What will be the output of the following Python code ??

def foo():
return total + 1
total = 0
print(foo())

a) 0
b) 1
c) error
d) none of the mentioned

 

How are required arguments specified in the function heading ??

a) identifier followed by an equal to sign and the default value
b) identifier followed by the default value within backticks (“)
c) identifier followed by the default value within square brackets ([])
d) identifier

 

Python Argument Parsing

 

What will be the output of the following Python code ??

def foo(fname, val):
print(fname(val))
foo(max, [1, 2, 3])
foo(min, [1, 2, 3])

a) 3 1
b) 1 3
c) error
d) none of the mentioned

 

How are default arguments specified in the function heading ??

a) identifier followed by an equal to sign and the default value
b) identifier followed by the default value within backticks (“)
c) identifier followed by the default value within square brackets ([])
d) identifier

 

How many keyword arguments can be passed to a function in a single function call ??

a) zero
b) one
c) zero or more
d) one or more

 

What is the value stored in sys.argv[0] ??

a) null
b) you cannot access it
c) the program’s name
d) the first argument

 

Python Argument Parsing

 

How are keyword arguments specified in the function heading ??

a) one-star followed by a valid identifier
b) one underscore followed by a valid identifier
c) two stars followed by a valid identifier
d) two underscores followed by a valid identifier

 

What is the type of sys.argv ??

a) set
b) list
c) tuple
d) string

 

What will be the output ??

def foo(k):
k[0] = 1
q = [0]
foo(q)
print(q)

a) [0]
b) [1]
c) [1, 0]
d) [0, 1]

 

Which module in the python standard library parses options received from the command line ??

a) getopt
b) os
c) getarg
d) main

 

Python Argument Parsing

 

What is the length of sys.argv ??

a) number of arguments
b) number of arguments + 1
c) number of arguments – 1
d) none of the mentioned

 

How are variable-length arguments specified in the function heading ??

a) one-star followed by a valid identifier
b) one underscore followed by a valid identifier
c) two stars followed by a valid identifier
d) two underscores followed by a valid identifier

 

What is the type of each element in sys.argv ??

a) set
b) list
c) tuple
d) string

 

What will be the output of the following ??

def foo(k):
k = [1]
q = [0]
foo(q)
print(q)

a) [0]
b) [1]
c) [1, 0]
d) [0, 1]

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!