1. Whether the parameter passing of Python is a value pass or a
Illustrate several forms of Python function parameter passing, and indicate whether a function argument is a value pass or a reference pass
First, Position parameters
The function is called when the parameter is passed according to the parameter position defined by the function. Example:
def print_hello (name, sex):
Sex_dict = {1:u ' Mr. ', 2:u ' lady '}
Print (' Hello%s '%s, welcome to Python world! '% (name, sex_dict.get (Sex, Mr. U ')))
# Two The order of the parameters must be one by one corresponding, and one less parameter can not
Print_hello (' Tanggu ', 2) #输出: Hello Tanggu, welcome to Python world!
Print_hello (' Tanggu ', 3) #输出: Hello Tanggu, Welcome to Python world! (the dictionary does not have a value of 3, so return "Sir")
# get () usage in dictionary: Dict.get (Key, Default=none)
#key-the key to find in the dictionary. Default-Returns the default value if the value of the specified key does not exist.
In-depth answers to 11 Python Foundation questions