top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Python Concepts for Data Science: *args and **kwargs

Function is an inevitable part in programming which reduces the redundant task to be performed. If the number of variables to be passed as function argument, then we can do it in normal way as:

def func(a,b,c):
    print("The statement is "+a+ " " + b + " " + c)
func("Data","Insight","Online")

Output
The statement is Data Insight Online

But if we don't know the number of function arguments, then we use special symbols as:

  • *args(Non-keyword argument)

  • **kwargs(Keyword argument)


*args

Keyword is not required while passing arguments. The arguments are passed as a tuple and these passed arguments make tuple inside the function with same name as the parameter excluding asterisk *.

def withArgs(*args):
    print(args)
withArgs(3,4,5)


Output
(3, 4, 5)

Here *args is used but we can use anything instead of args but * should be present before it. Example, *num, *dummy, etc.


**kwargs

If we want to pass keyword along with arguments, the **kwargs is used. The arguments are passed as dictionary.

def withKwargs(**foo):   
    print(foo)
    for key, value in foo.items():
        print("Key={},Value={}".format(key,value))
withKwargs(name="abc",surname="def",gender="M")

Output
{'name': 'abc', 'surname': 'def', 'gender': 'M'} Key=name,Value=abc Key=surname,Value=def Key=gender,Value=M 

As similar to *args, we can use any dummy value after double asterisk(**). Due to the dictionay nature, we accessed the values as key, value pair.


 
 
 

Σχόλια


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page