Home > database >  How to remove quotes and parentheses from return
How to remove quotes and parentheses from return

Time:09-28

I have to create a function in python that explicitly uses the return function. Every time I print, the output shows quotes and parentheses and I get docked marks and wanted to know how to remove them.

My code is:

def person(first_name, last_name, birth_year, hometown):                    
    info = (first_name   " "   last_name,str(birth_year),hometown)  
    return info

a = person('Lebron', 'James', 1984, 'Ohio')  

print(a)  

OUTPUT:

('Lebron James', '1984', 'Ohio')  

I need the Output to be:

Lebron James, 1984, Ohio

CodePudding user response:

You can just join the elements with a comma space string:

def person(first_name, last_name, birth_year, hometown):
    info = (first_name   " "   last_name,str(birth_year),hometown)
    return ', '.join(info)

a = person('Lebron', 'James', 1984, 'Ohio')

print(a)

Output as requested

CodePudding user response:

def person(first_name, last_name, birth_year, hometown):
    info = (first_name   " "   last_name,str(birth_year),hometown)
    return f"{info[0]}, {info[1]}, {info[2]}"

a = person('Lebron', 'James', 1984, 'Ohio')

print(a)
  • Related