How to pass dictionary items as function arguments in python?
*data interprets arguments as tuples, instead you have to pass **data which interprets the arguments as dictionary.
data = {'school':'DAV', 'class': '7', 'name': 'abc', 'city': 'pune'}
def my_function(**data):
schoolname = data['school']
cityname = data['city']
standard = data['class']
studentname = data['name']
You can call the function like this:
my_function(**data)
If you want to use them like that, define the function with the variable names as normal:
def my_function(school, standard, city, name):
schoolName = school
cityName = city
standardName = standard
studentName = name
Now you can use **
when you call the function:
data = {'school':'DAV', 'standard': '7', 'name': 'abc', 'city': 'delhi'}
my_function(**data)
and it will work as you want.
P.S. Don't use reserved words such as class
.(e.g., use klass
instead)