Arbitary arguments

Python program to show the arbitrary arguments. When program don’t know how many arguments are passed so arbitrary arguments are coming. Arbitrary arguments pack all arguments in tuple.

def show_magicians(         
*magicians
):
"""show_magicians
function show
information about
magicians """

print(magicians)

# calling a function
>>>show_magicians(
"Bob",
"alice")

Output: ("Bob","alice")


Here the values are come in tuple . But we need the information in series of list through loop. So we use for loop to pass arguments as a series of list.

def show_magicians(        
*magicians
):
""" show
information about
magicians """

for magician in
magicians :
print(
magician
)

>>>show_magicians(
"Bob",
"alice"
)

Output:

Bob
alice

Suppose we need positional argument with arbitrary argument. To add another argument with show_magicians. we need circus name with arbitrary arguments.

Leave a comment