Python Programming
June 16, 2025 at 10:34 AM
*Here are the Answers for the previous quizzes* ✅
*Q1. What will be the output of this code?*
def greet(name, msg="Welcome!"):
print(name, msg)
greet("Sam")
✅ *Answer: B. Sam Welcome!*
Since msg has a default value and no value is passed for it, it uses "Welcome!". So the function prints both name and msg.
*Q2. What does *args allow you to do in a function?*
✅ *Answer: C. Pass a variable number of positional arguments*
*args packs multiple positional arguments into a tuple. It allows functions to accept more arguments than originally defined.
*Q3. What is the correct way to define a function with default values?*
✅ *Answer: B. def func(x, y=10):*
In Python, parameters with default values must come after non-default ones. So x is required, y is optional.
*Q4. What will this function return?*
def multiply(*args):
result = 1
for num in args:
result *= num
return result
multiply(2, 3, 4)
✅ *Answer: A. 24*
The function multiplies all values: 2 * 3 * 4 = 24.
*Q5. Which of the following is used to pass a variable number of keyword arguments?*
✅ *Answer: C. **kwargs*
**kwargs packs multiple keyword arguments into a dictionary, allowing flexibility with named parameters.
*React with ❤️ if you're ready for the next topic*
Python Coding Challenge: https://whatsapp.com/channel/0029VaiM08SDuMRaGKd9Wv0L/1661
❤️
❤
👍
🇮🇳
🇵🇸
🇮🇱
😮
♥
🙏
😢
207