Reputation: 6075
Let's say I have this function code:
def dosomething(thing1, thing2='hello', thing3='world'):
print(thing1)
print(thing2)
print(thing3)
When calling it, I would like to be able to specify what thing3
is, but without having to say what thing2
is. (The code below is how I thought it might work...)
dosomething("This says 'hello fail!'", , 'fail!')
and it would say:
This says 'hello fail!'
hello
fail!
So is there a way to do it like that, or would I have to specify thing2
every time I wanted to say what thing3
was?
Upvotes: 3
Views: 96
Reputation: 22697
Yes, you can:
dosomething("This says 'hello fail!'", thing3 = 'fail!')
Upvotes: 3
Reputation: 2053
Use keyword arguments
dosomething("This says 'hello fail!'", thing3='fail!')
Upvotes: 7