Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the variable length parameter of python

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

This article will explain in detail how to use the python variable length parameter. 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.

Description

1. Add a decorator to the function.

2. If the number of parameters is uncertain, consider using variable length parameters.

For example, you are reading configuration items in some configuration files.

3. In order to implement the polymorphism of the function, or in the case of inheritance, the subclass needs to call some methods of the parent class.

Example

# coding:utf8 def powersum (power, * * args): print type (args) print "args is% s"% args for k in args.items v in args.items (): print k, ":", v print y = {'age':18,' name':'xxmcf'} powersum (0, * * y) powersum (0, args=y) on "how to use the python variable length parameter" is here. Hope that 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 articles functions more configuration good polymorphic practical content subclasses instances cases quantity files articles methods knowledge references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn Linux NVidia Shulou Technology