Get the App
SLTechnology News&Howtos  ›  Development  › 

How python implements the default parameters of a function

Shulou Source: shulou.com Published: 2022-06-01 04:23:44 10月11日 Update

This article will explain in detail how python implements the default parameters of the function. 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.

Default parameters of the function

> def foo (x = []): X.append (1)... Print x. > foo () [1] > foo () [1,1]

A safer approach is to:

Def foo (x=None):... If x is None:... X = []. X.append (1)... Print x. > > foo () [1] > > foo () [1] > > on "how to achieve the default parameters of python function" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: Functions parameters articles more good practical security practices content articles knowledge references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno macOS Redmi vpn