简体   繁体   English

如何从返回中删除引号和括号

[英]How to remove quotes and parentheses from return

I have to create a function in python that explicitly uses the return function.我必须在 python 中创建一个明确使用返回 function 的 function。 Every time I print, the output shows quotes and parentheses and I get docked marks and wanted to know how to remove them.每次打印时,output 都会显示引号和括号,我得到停靠标记,想知道如何删除它们。

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: OUTPUT:

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

I need the Output to be:我需要 Output 是:

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 Output 按要求

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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