Python Fundamentals / Functions and errors
Lesson 31 of 38
Default and keyword arguments
Parameters can have default values, and you can pass arguments by name to make calls clearer.
Key points
- def f(x, times=1):
- Call with f(x, times=3)
- Defaults go after required parameters
def shout(text, times=1):
return (text.upper() + "! ") * times
print(shout("hi", times=3))Quiz · +10 XP
In def f(a, b=2), what is b if you call f(5)?
Log in to save progress and earn XP.