Q: What is the type of each element in sys.argv?
Solution: It is a list of strings.
Q: What is the length of sys.argv?
Solution: The first argument is the name of the program itself. Therefore the length of sys.argv is one more than the number arguments.
Q: What will be the output of the following Python code? def foo(k): k[0] = 1 q = [0] foo(q) print(q)
Solution: Lists are passed by reference.
Q: How are keyword arguments specified in the function heading?
Solution: Refer documentation.
Q: How many keyword arguments can be passed to a function in a single function call?
Solution: Zero keyword arguments may be passed if all the arguments have default values.
Q: 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])
Solution: It is possible to pass function names as arguments to other functions.
Q: What will be the output of the following Python code? def foo(): return total + 1 total = 0 print(foo())
Solution: It is possible to read the value of a global variable directly.
Q: What will be the output of the following Python code? def foo(): total += 1 return total total = 0 print(foo())
Solution: It is not possible to change the value of a global variable without explicitly specifying it.
Q: 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))
Solution: When a list is a default value, the same list will be reused.
You Have Score    | /9 |