激活脚本的以下部分时,它将在结果中显示所有逗号和单引号(和括号)。
print(name, 'has been alive for', days, 'days', minutes, 'minutes and', seconds, 'seconds!')
因此,例如:
('Ryan', 'has been alive for', 10220, 'days', 14726544, 'minutes and', 883593928, seconds!')
我想清理它,所以看起来不错。那可能吗?
我所说的“好”是这样的:
Ryan has been alive for 10220 days, 14726544 minutes, and 883593928 seconds!
这是完整的脚本:
print("Let's see how long you have lived in days, minutes, and seconds!") name = raw_input("name: ") print("now enter your age") age = int(input("age: ")) days = age * 365 minutes = age * 525948 seconds = age * 31556926 print(name, 'has been alive for', days, 'days', minutes, 'minutes and', seconds, 'seconds!') raw_input("Hit 'Enter' to exit!: ")
你需要from __future__ import print_function。
from __future__ import print_function
在Python 2.x中,您正在执行的操作被解释为在使用3.x语法时打印一个元组。
例:
>>> name = 'Ryan' >>> days = 3 >>> print(name, 'has been alive for', days, 'days.') ('Ryan', 'has been alive for', 3, 'days.') >>> from __future__ import print_function >>> print(name, 'has been alive for', days, 'days.', sep=', ') Ryan, has been alive for, 3, days.