Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to Use *args and **kwargs in Python
- In this article, we'll discuss *args and **kwargs in Python along with their uses and some examples.
- When writing a function, we often need to pass values to the function. These values are called function arguments.
- Problem with Function Arguments
- Let's define a function to add two numbers in Python. We'll write it like this:
- def add(x, y):
- return x+y
- print(add(2,3))
- Output:
- 5
- What if you need to add three numbers? Simple, we can modify the function to accept three arguments and return their sum as:
- def add(x, y, z):
- return x+y+z
- print(add(2, 3, 5))
- for more:https://www.clictune.com/ez0C
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement