How to Print Multiple Arguments in Python?

An argument is a value that is passed within a function when it is called.They are independent items, or variables, that contain data or codes. During the time of call each argument is always assigned to the parameter in the function definition.

Example: Simple argument




def GFG(name, num):
    print("Hello from ", name + ', ' + num)
  
  
GFG("geeks for geeks", "25")

Output:

Hello from  geeks for geeks, 25

Calling the above code with no arguments or just one argument generates an error.

Variable Function Arguments

As shown above, functions had a fixed number of arguments. In Python, there are other ways to define a function that can take the variable number of arguments.
Different forms are discussed below:

Example:






def GFG(name, num="25"):
    print("Hello from", name + ', ' + num)
  
  
GFG("gfg")
GFG("gfg", "26")

Output:

Hello from gfg, 25

Hello from gfg, 26




def GFG(name, num):
    print("hello from %s , %s" % (name, num))
  
  
GFG("gfg", "25")

Output:

hello from gfg , 25




def GFG(name, num):
    print("hello from %(n)s , %(s)s" % {'n': name, 's': num})
  
  
GFG("gfg", "25")

Output:



hello from gfg , 25




def GFG(name, num):
    print("hello from {0} , {1}".format(name, num))
  
  
GFG("gfg", "25")

Output:

hello from gfg , 25




def GFG(name, num):
    print("hello from {n} , {r}".format(n=name, r=num))
  
  
GFG("gfg", "25")

Output:

hello from gfg , 25




def GFG(name, num):
    print("hello from " + str(name) + " , " + str(num))
  
  
GFG("gfg", "25")

Output:

hello from gfg , 25




def GFG(name, num):
    print(f'hello from {name} , {num}')
  
  
GFG("gfg", "25")

Output:

hello from gfg , 25




def GFG(*args):
    for info in args:
        print(info)
  
  
GFG(["Hello from", "geeks", 25], ["Hello", "gfg", 26])

Output:



[‘Hello from’, ‘geeks’, 25]

[‘Hello’, ‘gfg’, 26]




def GFG(**kwargs):
    for key, value in kwargs.items():
        print(key, value)
  
  
GFG(name="geeks", n="- 25")
GFG(name="best", n="- 26")

Output:

name geeks

n – 25

name best

n – 26


Article Tags :