Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use python default parameters

Shulou Source: shulou.com Published: 2022-06-02 15:46:31 10月03日 Update

This article focuses on "how to use the default parameters of python". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the default parameters of python.

Description

1. The definition location of the default parameter. Make sure that the default parameter with the default value is at the end of the parameter list.

2. When calling a function, if there are multiple default parameters, you need to specify the parameter name.

Example

Def print_info (name, title= ", gender=True):": param title: position: param name: names of classmates: param gender: True boys False girls"gender_text =" boys "if not gender: gender_text =" girls "print ("% s% s is% s "% (title, name) Gender_text) # hint: when you specify the default value of the default parameter You should use the most common value as the default value! Print_info ("Xiaoming") print_info ("Lao Wang", title= "monitor") print_info ("Xiaomei", gender=False) so far, I believe you have a deeper understanding of "how to use the default parameters of python". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Parameters content girls boys learning practical deeper location interest function classmate name multiple name example practicality practical common simple operation method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info Linux MySQL OPPO Reno