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.

Return a function

Python use the return statement to come up with a value . Sometimes, user don’t need direct Output, so it uses return statement. return statement ,using processed value. Suppose the user wants to come up with full name but we can’t come directly so,we use return statement.

def name(fname,lname):
""" return statement
using to come up
with full_name """

# store in a
variable
full_name =fname+"
"+lname
return
full_name.title()

>>>musicians
=name("vipul
","kunwar ")
print(musicians)

Output:

Vipul Kunwar