【问题标题】:In python, how to avoid quotes when I print a string?在python中,打印字符串时如何避免引号?
【发布时间】:2017-06-03 05:56:40
【问题描述】:
A='abcdef'

print 'My sequence is %r' % A

输出是:

My sequence is 'abcdef'

我想得到这样的结果:

My sequence is abcdef

如何避免引号?

【问题讨论】:

  • 试试%s 而不是%r

标签: python-2.7 printing


【解决方案1】:

这是因为%r 如何指示 Python 插入具有特定格式的字符串。

你可以阅读更多关于这个here

要在另一个字符串中插入一个字符串,请使用%s 选项。

更好的是,做:

"my sequence is {}".format(A)

【讨论】:

    猜你喜欢
    • 2021-06-30
    • 1970-01-01
    • 2023-01-09
    • 2022-01-13
    • 2021-05-24
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    • 2016-07-17
    相关资源
    最近更新 更多