What is the output of the following display_person() function calldef display_person(*args): for i in args: print(i)display_person(name="Emma", age="25")TypeErrorEmma25nameage
Question
What is the output of the following display_person() function calldef display_person(*args): for i in args: print(i)display_person(name="Emma", age="25")TypeErrorEmma25nameage
Solution
The code you provided will result in a TypeError. This is because the function display_person(*args) is expecting positional arguments, but you are providing keyword arguments (name="Emma", age="25").
If you want to use keyword arguments, you should define your function with **kwargs instead of *args. Here's how you can do it:
def display_person(**kwargs):
for key, value in kwargs.items():
print(key, value)
display_person(name="Emma", age="25")
This will output:
name Emma
age 25
In this version of the function, kwargs is a dictionary that contains the names of the arguments as keys and their values as the dictionary values.
Similar Questions
What is the output of the following display() function calldef display(**kwargs): for i in kwargs: print(i)display(emp="Kelly", salary=9000)TypeErrorKelly9000(’emp’, ‘Kelly’)(‘salary’, 9000)empsalary
What is the output of the following function calldef fun1(name, age=20): print(name, age) fun1('Emma', 25)
What is the output of the following code?class Person: def __init__(term, name, age): term.name = name term.age = agep1 = Person("term","Raghu", 36)print(p1.name)print(p1.age)
What does the program below display?full_name = "Jane"full_name = full_name + "Brown"print( full_name )*
what is the output of following python code? class myclass: def display(self,a): print(a)o=myclass()o.display("Hello World")
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.