ProgrammingHardWipro · Accenture · Capgemini pattern
What does the following Python 3 code print? def f(a, b, *args): return a, b, args print(f(1, 2, 3, 4, 5))
- A. (1, 2, (3, 4, 5, 5))
- B. (1, 2, 3, 4, 5)
- C. (1, 2, (3, 4, 5))
- D. (1, 2, [3, 4, 5])
Correct answer: C. (1, 2, (3, 4, 5))
a and b take the first two positional values; every remaining positional argument is collected into the args tuple.
More Python Programming questions
- What does the following Python 3 code print? def f(kwargs): return sorted(kwargs.items()) print(f(b=2, a=1, c=3))
- What does the following Python 3 code print? def f(a, , b): return a + b try: print(f(1, 2)) except TypeError: print("err")
- What does the following Python 3 code print? l = [1, 2, 3] print(l, sep="-")
- What does the following Python 3 code print? print([1, 2, 3], [4, 5], sep=",")
- What does the following Python 3 code print? d = {"a": 1, "b": 2} print(d)
- What does the following Python 3 code print? a, b, c = [1, 2, 3, 4, 5] print(a, b, c)