ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
def f(**kw):
return list(kw)
print(f(b=1, a=2), f(**dict(z=0), y=1), f(**{"1": 1}))- A. ['a', 'b'] ['y', 'z'] ['1']
- B. ['b', 'a'] ['z', 'y'] TypeError
- C. ['b', 'a'] ['y', 'z'] ['1']
- D. ['b', 'a'] ['z', 'y'] ['1']
Correct answer: D. ['b', 'a'] ['z', 'y'] ['1']
**kw preserves the order in which keyword arguments were passed (guaranteed since Python 3.6). Keys unpacked with ** only have to be strings, not valid identifiers, so '1' is accepted.
More Python Programming questions
- What is printed? python class A: def getitem(self, k): return k a = A() print(a[1], a[1:3], a[::2], a[1, 2:3], a[...])
- What is printed? python print([int(t, 0) for t in " 12000 t-0b101 +7 ".split()])
- What is printed? python import sys print(sys.getintmaxstrdigits()) try: s = str(10 4300) except ValueError: print("too long")
- What is printed? python print(len(str(2 1000 5 1000)))
- What is printed? python rows = [(2, 'b'), (1, 'z'), (2, 'a'), (1, 'y')] print(sorted(rows, key=lambda t: (-t[0], t[1])))
- What is printed? python print(sorted(['bb', 'a', 'cc', 'd', 'ee'], key=len, reverse=True))