print() 在结果中显示引号 [英] print() is showing quotation marks in results

查看:48
本文介绍了print() 在结果中显示引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当脚本的以下部分被激活时,它会在结果中显示所有逗号和单引号(和括号).

print(name, '已经存活', days, 'days', minute, 'minutes and', seconds, 'seconds!')

例如:

('Ryan', 'has been living for', 10220, 'days', 14726544, 'minutes and', 883593928, seconds!')

我想清理它,所以它看起来不错.那可能吗?

好",我的意思是这样的:

Ryan 已经活了 10220 天 14726544 分 883593928 秒!

这里是完整的脚本:

print("让我们看看你活了多少天、分、秒!")name = raw_input("姓名:")print("现在输入你的年龄")年龄 = 整数(输入(年龄:"))天数 = 年龄 * 365分钟 = 年龄 * 525948秒 = 年龄 * 31556926打印(名称,'已经活着',天,'天',分钟,'分钟和',秒,'秒!')raw_input("按回车键退出!:")

解决方案

你需要from __future__ import print_function.

在 Python 2.x 中,您正在执行的操作被解释为打印一个元组,而您使用的是 3.x 语法.

示例:

<预><代码>>>>名称 = '瑞安'>>>天数 = 3>>>打印(名称,'已经活着',天,'天.')('Ryan', '已经活着', 3, 'days.')>>>从 __future__ 导入 print_function>>>打印(名称,'已经活着',天,'天.',sep=',')瑞安,已经活了 3 天了.

When the below portion of the script is activated, it shows all the commas and single quotes (and parentheses) in the results.

print(name, 'has been alive for', days, 'days', minutes, 'minutes and', seconds, 'seconds!')

So, for instance:

('Ryan', 'has been alive for', 10220, 'days', 14726544, 'minutes and', 883593928, seconds!')

I want to clean it up, so it looks good. Is that possible?

By "good", I mean something like this:

Ryan has been alive for 10220 days, 14726544 minutes, and 883593928 seconds!

Here is the full script:

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!: ")

解决方案

You need from __future__ import print_function.

In Python 2.x what you are doing is interpreted as printing a tuple, while you are using the 3.x syntax.

Example:

>>> 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.

这篇关于print() 在结果中显示引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆