This is a memo.
The name of the variable to put in parentheses when you define the function. The title is python, but the same name is used in other languages such as php.
#↓ ↓ ↓ Formal parameters: name, age
def birthday(name, age):
print(f'{name}Mr.{age}Happy birthday')
Initial values can be set for formal arguments.
If there is no initial value, an error will occur if there are not enough arguments to pass. If there is an initial value, no error will occur.
▼ Function with initial value set
def birthday(name='TODOROKI', age="24"):
print(f'{name}Mr.{age}Happy birthday')
#No arguments
birthday()
>Happy 24th birthday, TODOROKI
#Specify only one argument
birthday('AAA')
>Happy 24th birthday, AAA
#Specify which argument
birthday(age='31')
>Happy 31st birthday, TODOROKI
#No initial value of formal argument
def birthday(name, age):
print(f'{name}Mr.{age}Happy birthday')
#Call with no arguments
birthday()
>TypeError: birthday() missing 2 required positional arguments: 'name' and 'age'
Error type: TypeError Content: Missing two arguments
Recommended Posts