Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set the default value for the parameter of python function

Shulou Source: shulou.com Published: 2022-06-03 09:38:34 11月15日 Update

This article mainly introduces the python function parameters how to set the default value, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

When you write a function, you can specify a default value for each parameter.

1. Python will use the specified argument value when providing arguments to the parameter in the calling function, otherwise the default value of the parameter will be used.

2. When using default values, the formal parameters with no default values must be listed in the formal parameter list, and then the arguments with default values must be listed.

Example

> def greet_user (username): the parameters in parentheses here are formal parameters "display simple greetings" print ("Hello,"+ username.title () +"! ") > greet_user ('chenyu') Hello, Chenyu! > Thank you for reading this article carefully. I hope the article" how to set the default value of python function parameters "shared by the editor will be helpful to you. At the same time, I hope you will support it. Pay attention to the industry information channel, more related knowledge is waiting for you to learn!

Tags: Formal parameters functions articles values interests parameters at the same time examples parentheses more friends knowledge editing industry information information channels channels references learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft Shulou Tech Info Redmi Linux