【发布时间】:2020-08-04 18:48:18
【问题描述】:
这是我的代码的一部分:
def LeapYear(year=0,month=0,day=0):
.
.
.
# as it's a long code I've jumped the unnecessary things.
.
.
.
return ("Today is the {}th day of the year!".format(T))
它返回这样的字符串(带引号):
'Today is the 70th day of the year!'
但我希望它像这样返回(不带引号):
Today is the 70th day of the year!
我不想使用函数来执行此操作,并且由于我有很多这样的行,我不希望解决方案很长,有没有办法?
【问题讨论】:
-
引号不是字符串的一部分。如果你
print它,引号将不会出现。 -
没有引号是什么意思?它是一个字符串,并且字符串在 python 中总是用“引号”表示。你能描述一下你想在这里做什么吗?
-
只有打印出来才能看到字符串;单引号 not 是返回值的一部分;当需要在交互式解释器中显示值的表示时,它们由
str.__repr__添加。 -
@Moty.R
It's python syntax。另外,为什么要返回一个冗长的字符串,打印年份并将年份返回为Int。