Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 1 : (2, 1) / (2, 1)

Advertisement

Detailed Solution

सही उत्तर (2, 1) / (2, 1) है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Python code? `def f(*a, **k): return len(a), len(k)` / `print(f(1, 2, x=3))` / निम्नलिखित Python कोड का आउटपुट क्या होगा? `def f(*a, **k): return len(a), len(k)` / `print(f(1, 2, x=3))`

1.
(2, 1) / (2, 1)
2.
(3, 0) / (3, 0)
3.
Error — keyword argument not accepted / त्रुटि — keyword argument स्वीकार नहीं
4.
(2, 0) / (2, 0)

Correct Answer: (2, 1) / (2, 1)

`*a` collects the two positional arguments into a tuple of length 2, and `**k` collects the single keyword argument into a dict of length 1, so the function returns (2, 1). The trap is counting `x=3` among the positional arguments. / `*a` दो positional argument को length 2 के tuple में समेटता है, और `**k` एक keyword argument को length 1 के dict में समेटता है, अतः function (2, 1) लौटाता है। जाल `x=3` को positional argument में गिनना है।

Downloaded from PrepSnap (prepsnap.in)