Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the rules for the use of python parameter combinations

Shulou Source: shulou.com Published: 2022-06-03 17:38:38 09月19日 Update

This article will explain in detail the rules for the use of python parameter combinations. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

When using functions, you will inevitably come into contact with the parameters in python, and these parameters can be used together, so let's take a look at the specific combination rules.

Use Rul

1. When defining a function, five parameters can be combined.

2. The order in which the five parameters are defined must be: position parameter, default parameter, variable parameter, named keyword parameter, keyword parameter.

Combination of location parameters and default parameters

Def Person (name,age = 20): print (name,age) Person ('zhangsan') Person (' zhangsan', 20)

Position parameter, default parameter, variable parameter combination

Def Person (name, age=20, * args): for i in args: print (I) print (name, age) Person ('zhangsan') Person (' zhangsan', 22, "Beijing") Person ('zhangsan', age=22,' Shanghai') about "what are the rules for the use of python parameter combinations". I hope the above content can be helpful to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.

Tags: Parameters combinations rules locations articles keywords functions more variable good practical inevitable content can be passed articles knowledge order references help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info NVidia vpn MariaDB