简体   繁体   中英

How to remove quotes and parentheses from return

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

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM