30 Python Programming Questions on Function Arguments
Q 1. Define a function with two positional arguments and call it with values 10 and 20.
Expected Output:
30
Q 2. Define a function with a default argument and call it without providing the default value.
Expected Output:
Hello, Guest!
Q 3. Define a function with keyword arguments and call it using named arguments.
Expected Output:
My name is Alice and I am 30 years old.
Q 4. Define a function with variable-length positional arguments and call it with multiple values.
Expected Output:
Hello world from Python
Q 5. Define a function with variable-length keyword arguments and call it with multiple named arguments.
Expected Output:
{'name': 'John', 'age': 25, 'city': 'New York'}
Q 6. Define a function with both default and keyword arguments and call it with some keyword arguments.
Expected Output:
Hello, Alice!
Q 7. Define a function that uses positional arguments and keyword arguments together.
Expected Output:
Eve is 28 years old and lives in Paris.
Q 8. Define a function with variable-length positional arguments and default arguments.
Expected Output:
20
Q 9. Define a function that prints a list of names using variable-length positional arguments.
Expected Output:
Alice
Bob
Charlie
Q 10. Define a function that returns the sum of a list of numbers and an optional multiplier.
Expected Output:
24
Q 11. Define a function with a required positional argument and an optional keyword argument.
Expected Output:
Hi, Dave!
Q 12. Define a function that accepts variable-length keyword arguments and returns the count of those arguments.
Expected Output:
3
Q 13. Define a function that combines a list of strings into a single string using variable-length arguments.
Expected Output:
Python-is-fun
Q 14. Define a function that takes a positional argument and a variable-length keyword argument and returns them as a dictionary.
Expected Output:
{'positional': 'value', 'key1': 'val1', 'key2': 'val2'}
Q 15. Define a function that calculates the area of a rectangle using keyword arguments.
Expected Output:
50
Q 16. Define a function that takes a fixed positional argument and an arbitrary number of additional positional arguments, and returns their sum.
Expected Output:
16
Q 17. Define a function with default positional arguments and call it with and without providing values for those arguments.
Expected Output:
Hi Hi Hi
Hello Hello Hello Hello Hello
Q 18. Define a function that takes a list as a positional argument and a default value to append to the list.
Expected Output:
[1, 2, 3, 'default']
[1, 2, 3, 'extra']
Q 19. Define a function with a mix of positional and variable-length arguments, and return the total number of arguments passed.
Expected Output:
3
Q 20. Define a function that uses a default keyword argument and call it with and without specifying the keyword argument.
Expected Output:
Hello World
Goodbye World
Q 21. Define a function with both default and variable-length positional arguments, and call it with different numbers of arguments.
Expected Output:
Data1: 1, 2, 3, Default: N/A
Data2: 4, 5, Default: Custom
Q 22. Define a function that accepts a variable-length list of numbers and calculates their average.
Expected Output:
3.0
0
Q 23. Define a function that takes a positional argument and variable-length keyword arguments, and returns the positional argument and the sum of the keyword arguments' values.
Expected Output:
Alice: Total = 30
Q 24. Define a function with positional and default arguments and call it with different combinations of arguments.
Expected Output:
Option: color, Value: default
Option: size, Value: large
Q 25. Define a function that accepts a fixed number of positional arguments and an arbitrary number of keyword arguments, and returns the keyword arguments as a dictionary.
Expected Output:
{'title': 'Monthly Report', 'author': 'John Doe', 'pages': 10}
Q 26. Define a function with positional arguments and a variable-length list of default values, and call it with various arguments.
Expected Output:
[15, 25, 35]
[25, 35]
Q 27. Define a function that takes a list and a variable-length list of additional items to append to the list.
Expected Output:
[1, 2, 3, 4, 5, 6]
Q 28. Define a function with keyword arguments to specify configuration options and call it with different configurations.
Expected Output:
{'theme': 'dark', 'language': 'English'}
{'theme': 'light'}
Q 29. Define a function with a required positional argument and variable-length keyword arguments, and print the argument names and values.
Expected Output:
Name: Alice
age: 30
city: London
Q 30. Define a function that takes a positional argument and a variable-length list of positional arguments, and returns the count of the total arguments.
Expected Output:
4
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!