Function definition:
def function name ():
Member function (function Implementation code segment)
Function call:
Without argument:
Function name ()
There are parameters:
Function name (parameter values)
# Function definition DEF San (): Print ( " ! Shelter, shade " ) # call the function can be reused San () San ()
# Cash # user input: card, password and the withdrawal amount # ATM output: card, RMB DEF get_money_from_ATM (card_num, passwd, Money = 100): # Money is the default parameter Print (card_num) Print (passwd) Print (Money) IF of the type (card_num) == str and of the type (passwd) == str and of the type (Money) == int: Print ( " meet the requirements it can begin to withdraw money!! " ) Pass
# ordinary parameters get_money_from_ATM ( " 11,122,233,344,455 " , " 123456 " 200) # normal get_money_from_ATM("11122233344455",123456,200) # 异常
指定参数:
get_money_from_ATM(card_num="11122233344455",passwd="123456",money=200)
get_money_from_ATM(card_num="11122233344455",passwd="123456")
And parameter arguments
Parameter: the formal parameter. Defining a function, using parameter . The equivalent of placeholders.
Arguments: the function is called, is the argument .
It must be determined value. So the argument is assigned in advance.
General parameters: positional parameters. According to the order parameter, into the argument.
Specified parameters: not in accordance with the order parameter. Parameter passing requirements: the parameter name argument value =
Default parameters: a parameter to a default value, only in the last parameter, can not put the middle