Function

Python Quiz for Functions – 05

Python Quiz for Functions

Functions in Python enable programmers to group related statements together, making the code more readable, reusable, and efficient. Whether you’re a beginner trying to grasp the basics of function syntax or an experienced coder aiming to test your understanding, this Python quiz for functions is designed to challenge and educate you. From simple function declarations to intricate details about parameters and return values, get ready to put your Python knowledge to the test!

0%
7

Python Functions – 05

Level: Intermediate

1 / 10

1. What is a lambda function?

2 / 10

2. What is the output of the following code:

def update_with_defaults(d, defaults):
  for key, value in defaults.items():
    d.setdefault(key, value)
  return d

# Example usage
print(update_with_defaults({"a": 1, "b": 2}, {"b": 3, "c": 4}))

3 / 10

3. What is the output of the following code:

def get_max_value(d):
  return max(d.values())

print(get_max_value({"a": 1, "b": 2, "c": 3}))

4 / 10

4. What is a function with variable length arguments?

5 / 10

5. What is a nested function?

6 / 10

6. What is the output of the following code:

def count_length_of_values(d):
  return {k: len(v) for k, v in d.items()}

print(count_length_of_values({"a": "apple", "b": "banana"})['b'])

7 / 10

7. What is the output of the following code:

def check_keys_exist(d, keys):
  return all(key in d for key in keys)

print(check_keys_exist({"a": 1, "b": 2, "c": 3}, ["a", "b"]))

8 / 10

8. What is the difference between a positional argument and a keyword argument?

9 / 10

9. What is the output of the following code:

def dict_to_tuples(d):
  return list(d.items())

print(dict_to_tuples({"a": 1, "b": 2, "c": 3})[1])

10 / 10

10. What are the benefits of using functions?

Your score is

0%