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")
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")
Solution
The code you provided will actually result in an error. The reason is that you're trying to pass keyword arguments (name="Emma", age="25") to a function that accepts only positional arguments (*args).
If you want to pass keyword arguments, you should use **kwargs in your function definition, like this:
def display_person(**kwargs):
for key, value in kwargs.items():
print(f"{key}: {value}")
display_person(name="Emma", age="25")
This will output:
name: Emma
age: 25
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)
What is the output of the following function calldef fun1(name, age=20): print(name, age) fun1('Emma', 25)
what is the output of following python code? class myclass: def display(self,a): print(a)o=myclass()o.display("Hello World")
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 )*
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.