⊗pyPmFnMPP 11 of 128 menu

Passing Multiple Parameters to a Function in Python

Let's say we have a function that takes several numeric parameters:

def func(num1, num2): return num1 + num2 print(func1(2, 3))

When the function is called, the given numbers 2 and 3 will be placed in the variables num1 and num2, respectively.

But there are cases when you need to pass many parameters when calling a function, the number of which is unknown in advance. In Python, you can set only one variable when declaring a function, from which a tuple of all the parameters passed during the call will later be output. To do this, you need to specify the symbol * before this variable. Such a variable is usually called args, but you can give it any other name. And to output all the parameters, you need to write this variable in the function body, but without *:

def func(*args): return args print(func(1, 2, 3)) # (1, 2, 3)

Then you can perform any other operations with the received parameters. Let's get their sum:

def func(*args): return sum(args) print(func(1, 2, 3)) # 6

Write a function that will take an unlimited number of usernames as parameters and output them to the console as a tuple.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline