Python *args **kwargs | Non-Keyword Arguments | Keyword Arguments | *args **kwargs | Python Special
Автор: Anuurag Edlabadkar
Загружено: 2022-01-13
Просмотров: 20
Описание:
Day 1: Python - Python Programming - Features of Python - • Python - Python Programming - Features of ...
Day 2: Python Data Type - • Python Data Type | Python Standard Data Ty...
Day 3: Python String Inbuilt Functions Part 1 - • Python Data Type | String | String Inbuil...
Day 4: Python String Inbuilt Functions Part 2 - • Python String Inbuilt Functions | String F...
Day 5: Python String Data Type Slicing and Indexing - • Python String Data Type Slicing and Indexi...
Day 6: Python List Inbuilt Functions • Python List Inbuilt Functions | List Inbui...
Day 7: Python List Slicing and Indexing • Python List Indexing & Slicing | List Inde...
Day 8: Python Tuple Slicing and Indexing • Python Tuple Indexing and Slicing | Python...
Day 9: Python Set Inbuilt Functions • Python Set Inbuilt Functions | Python Set ...
Day 10: Python Dictionary Inbuilt Functions • Python Dictionary Inbuilt Functions | Pyth...
Day 11: Python Inbuilt Exception Handling • Python Inbuilt Exception Handling | Inbuil...
Day 12: Python Inbuilt Exception Handling Part II • Python Inbuilt Exception Handling | Python...
Day 13: Python Special Argument *args, **kwargs • Python *args **kwargs | Non-Keyword Argume...
github: https://github.com/gitanuurage/gitanu...
Special Symbols Used for passing arguments:-
1. *args (Non-Keyword Arguments)
2. **kwargs (Keyword Arguments)
*args
The special syntax *args in function definitions in python is used to pass a variable number of arguments to a function. It is used to pass a non-key worded, variable-length argument list.
1. The syntax is to use the symbol * to take in a variable number of arguments; by convention, it is often used with the word args.
2. What *args allows you to do is take in more arguments than the number of formal arguments that you previously defined. With *args, any number of extra arguments can be tacked on to your current formal parameters (including zero extra arguments).
3. For example : we want to make a multiply function that takes any number of arguments and able to multiply them all together. It can be done using *args.
4. Using the *, the variable that we associate with the * becomes an iterable meaning you can do things like iterate over it, run some higher-order functions such as map and filter, etc.
**kwargs
The special syntax **kwargs in function definitions in python is used to pass a keyworded, variable-length argument list. We use the name kwargs with the double star. The reason is because the double star allows us to pass through keyword arguments (and any number of them).
1. A keyword argument is where you provide a name to the variable as you pass it into the function.
2. One can think of the kwargs as being a dictionary that maps each keyword to the value that we pass alongside it. That is why when we iterate over the kwargs there doesn’t seem to be any order in which they were printed out.
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: