Problem regarding arguments in python language

The link to code is - https://ide.codingblocks.com/s/241350 .

In this code, first function (named show1 ) prints comma after last word in tuple but second function (named show2 ) does not print comma after last word in tuple . Please explain why is this error coming up.

Hey @abhaygarg2001, this is happening in show1 due to the fact that when you use *args as an argument, it expects you to pass more than 1 arguments and hence prints a comma after the first element in the tuple. If you would pass more than 1 element for *args , then it won’t show the comma after printing 2 or more elements. You can run the following code :

def show1(a,b,c,*args):
    print(args)

show1(1,2,3,"abhay","aayush")

However, if you still want to print only ‘abhay’ without a comma, then you can run the following code :

def show1(a,b,c,*args):
    print(*args)

show1(1,2,3,"abhay")

Hope this helps.
Happy Learning :slight_smile: