17.Var-args Methods in python-Passing Variable number of Positional & keyword arguments to Function

preview_player
Показать описание
In this video we are going to disucss about "Var-arg" Methods in Python , if you are a Java developer this term will be familiar to you , yes when i say Var-arg Methods i Wanted to say a function that takes Any number of arguments Based on the user

Since i have explained you about the positional and keyword arguments in Strings , same is the case here and in the previous video I have explained in detail about the Parameters and their types in python to a function please watch the video to understand it in a better way

in this video i have explained you to create both Var-args for Poistional and keyword arguemnts methods

first of all in order to create a function with Variable number of positional arguments , Therefore In order to create it first of all we should use the "Unpacking operator" that is our "Asterisk" "*" operator in Python

to make you understand this let me create one

def example(*x):
for y in x:
print(y)

the above is the simplest example of all , but the more advance example is given in the video which is in itself simple one
Well the above function will print the list of all arguments that the user is giving to the function

In order to create a function with variable number of keyword arguments we just have replace single Asterisk with Double as follows

def example2(**x):
for y in x:
print(y,"=",x[y])

therefore the above function will print all the keyword values or parameters passed to the function. The more complex example is given in the video itself

17.Var-args Methods in python-Passing Variable number of Positional & keyword arguments to Function

Subscribe and Share the Channel with your Computer Science Friends and Others who are interested LearningWithFaraz

#Var-args #Python
Рекомендации по теме