ProgrammingModerateTCS NQT · Infosys pattern
What is printed?
What is printed?
def f(*args, **kw):
return len(args), sorted(kw)
print(f(1, 2, *[3, 4], a=5, **{"b": 6}))- A. (3, ['a', 'b'])
- B. (2, ['a', 'b'])
- C. (4, ['a', 'b'])
- D. (4, ['b', 'a'])
Correct answer: C. (4, ['a', 'b'])
*[3, 4] unpacks into two more positional arguments (4 in total), and **{"b": 6} adds a keyword argument. sorted() on a dict returns its sorted keys.
More Python Programming questions
- What is printed? python class A: count = 0 def init(self): A.count += 1 self.count = 10 a = A(); b = A() b.count += 5 print(A.count…
- What is printed? python it = iter([1, 2, 3, 4, 5]) pairs = list(zip(it, it)) print(pairs, list(it))
- What is printed? python import copy a = [[1, 2], [3]] b = copy.copy(a) c = copy.deepcopy(a) a[0].append(9) a.append([4]) print(b, c)
- What is printed? python print(bool([]), bool([0]), bool(""), bool(" "), None == False, 0 == False)
- What is printed? python def countcalls(fn): def wrapper(a): wrapper.calls += 1 return fn(a) wrapper.calls = 0 return wrapper @countcalls…
- What is printed? python def make(): acc = [] for i in range(3): def f(x, i=i): return x i acc.append(f) acc.append(lambda x: x + i) return…