Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何让我的代码返回答案而不使用额外的'';和()_Python_Python 3.x - Fatal编程技术网

Python 如何让我的代码返回答案而不使用额外的'';和()

Python 如何让我的代码返回答案而不使用额外的'';和(),python,python-3.x,Python,Python 3.x,如何让我的代码返回答案,而不使用额外的'和() 您返回了一个元组,而不是一个字符串 尝试只返回必要的值,然后打印输出 return len(new_string), total_e 在职能之外, new_len, total_e = analyze_text(text) percent = 100 * total_e / new_len print( "The text contains {} alphabetic characters, of which {} ({}) are 'e'".

如何让我的代码返回答案,而不使用额外的
'
()


您返回了一个元组,而不是一个字符串

尝试只返回必要的值,然后打印输出

return len(new_string), total_e
在职能之外,

new_len, total_e = analyze_text(text)
percent = 100 * total_e / new_len

print( "The text contains {} alphabetic characters, of which {} ({}) are 'e'".format(new_len, total_e, percent)) 

请下次提供更可读的代码清单

您可以简单地使用每个字符串对象可以执行的format()方法。 这可能会有帮助。

在您的情况下,它将是这样的:

return "The text contains {} alphabetic characters, of which {} ({}) are 'e'".format(len(new_string), total_e, percentage)
return "The text contains {} alphabetic characters, of which {} ({}) are 'e'".format(len(new_string), total_e, percentage)