Home >Backend Development >Python Tutorial >Default parameter usage of Python functions
Explanation
1. The formal parameter specifying a default value must be at the end of all parameters without a default value, otherwise a syntax error will occur.
No need to pass in default value parameters. If default parameters are passed in, the default values will be overwritten.
2. When using this format to define a function, the formal parameters specified with default values must be at the end of all parameters without default values, otherwise a syntax error will occur.
Examples
def enroll(name, gender, age=6, city='Beijing'): print('name:', name) print("gender:", gender) print("age:", age) print("city:", city) print(enroll('张三', '一年级')) print('************************** ') print(enroll('李四', '二年级', 7))
1. Simple and easy to use, compared with traditional languages such as C/C, Java, and C# , Python’s requirements for code format are not so strict;
2. Python is open source, everyone can see the source code, and can be transplanted and used on many platforms;
3 , Python is object-oriented and can support process-oriented programming and object-oriented programming;
4. Python is an interpreted language. Programs written in Python do not need to be compiled into binary code and can be run directly from source code. Program;
5. Python is powerful and has many modules, which can basically realize all common functions.
The above is the detailed content of Default parameter usage of Python functions. For more information, please follow other related articles on the PHP Chinese website!