-
Notifications
You must be signed in to change notification settings - Fork 3
Args and kwargs in Python
surendrabisht edited this page Jul 13, 2020
·
2 revisions
Default parameters:
def power(no, value=2):
return no**2;
power(9)
power(9,3)
args :
single star operator. Consider values as tuple.
def func(*argv):
for arg in argv:
print(arg)
func('There', 'can', 'be', 'any',"no","of", "arguments","passed")
kwargs :
double start operator . key arguments. consider values as dictionary collection.
def func(**kwags):
for k,v in kwargs.items():
print(f"{k} : {v}")
d= {"name":"surendra", "age":26}
func(**d)
or
func("name":"surendra", "age":26)
While defining functions with all above type of parameters, order of parameters should be as follows:
- Parameter
- *args
- default parameters
- **kwargs
Keep Learning. Never Settle! 😊
- Home
- 1.Introduction To Python
- 2. DataTypes
- 3. Strings and Slicing of collection
- 4.If else & Loops
- 5. Break, continue, pass
- 6. Functions
- 7. Modules
- 8. Clarifying basics
- 9. File Handling
- 10. Exception Handling
- 11. Dig into Collections
- 12. Iterators, Generators and list comprehension
- 13. lambdas , map, filter and other concepts
- 14. args, kwargs an default parameters
- 15. Functional Programming
- 16. OOPs