1

I'd like to just start by saying I'm completely new to python. I was learning via udemy, and the lesson was on defining functions.

There was a thing where you can give default values in parameters. Idk what it called but when you call the function, the first parameter takes priority??

def print_something(name = "someone", age= "unknown"):
     print("My name is", name, "and my age is", age)
print_something(bob)

=

my name is bob and my age is unknown

MY QUESTION is, for the above code, what if I wanted to put the age but no name so it would read out like

=

my name is someone and my age is 16
ayowassup
  • 11
  • 3
  • They are called keyword arguments, and `print_something('bob')`, `print_something(age=16)`, `print_something('bob', age=16)`, etc would all be valid calls. – costaparas Jan 22 '21 at 05:23

2 Answers2

1

Use a keyword argument :

print_something(age=16)
flakes
  • 21,558
  • 8
  • 41
  • 88
0

i suppose you can try

print_something(age="16")
George Joseph
  • 5,842
  • 10
  • 24