[Extra] Dynamic Arguments
Using *args in your Function
*args in your FunctionExample: Sum of Numbers
def sum_numbers(*args):
result = 0
for num in args:
result += num
return result
# Calling the function with different numbers of arguments
print(sum_numbers(1, 2, 3)) # Output: 6
print(sum_numbers(10, 20, 30, 40)) # Output: 100
print(sum_numbers(5)) # Output: 5Using **kwargs in your Functions
**kwargs in your FunctionsExample: A function that can display various dictionary combinations
Last updated