Functions & Scope · Question 9 · Medium

A function receives keyword arguments through **info. What does sorted(info) give here?

def show(**info):
    return sorted(info)

print(show(city="Pune", age=21))
  1. ['age', 'city']
  2. ['city', 'age']
  3. [21, 'Pune']
  4. [('age', 21), ('city', 'Pune')]
Answer and explanation

Answer: A. ['age', 'city']

Explanation: **info collects the keyword arguments into the dictionary {'city': 'Pune', 'age': 21}. Iterating over a dictionary gives its keys, and sorted returns them as a list in alphabetical order.

Previous: The tag function uses a dictionary as a default parameter value. What do the… · Next: The hit function tries to increase a module-level counter without declaring it…

Practise functions & scope

Try a fresh set of functions & scope questions with an explanation after every answer, free and without signing up: Functions & Scope practice. Or sit a full placement mock test.

More functions & scope questions

More python practice

Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge