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)