Advertisement
sissou123

Untitled

Mar 24th, 2022
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. How to Use *args and **kwargs in Python
  2. In this article, we'll discuss *args and **kwargs in Python along with their uses and some examples.
  3.  
  4. When writing a function, we often need to pass values to the function. These values are called function arguments.
  5.  
  6. Problem with Function Arguments
  7. Let's define a function to add two numbers in Python. We'll write it like this:
  8.  
  9. def add(x, y):
  10.    return x+y
  11.  
  12. print(add(2,3))
  13. Output:
  14.  
  15. 5
  16. What if you need to add three numbers? Simple, we can modify the function to accept three arguments and return their sum as:
  17.  
  18. def add(x, y, z):
  19.    return x+y+z
  20.  
  21. print(add(2, 3, 5))
  22. for more:https://www.clictune.com/ez0C
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement