t = ("rotation: %d%%\t [note]"% 123)
in jupyter notebook when you type t and run cell
output: rotation: 123%\t [note]
我想得到的结果如下:
输出:旋转:123%[note]
答案 0 :(得分:1)
这是jupyter笔记本的体现。使用str
默认使用的print
时,我们得到
rotation: 123% [note]
但是,当您在交互式python中键入t
时,将使用repr()
来代替。可以使用任何交互式python轻松复制它:
>>> t = ("rotation: %d%%\t [note]"% 123)
>>> t
'rotation: 123%\t [note]'
>>> print(t)
rotation: 123% [note]
区别在于repr()
给出了对象的表示形式,以便可以通过代码重新创建它,并且对于调试最有用。 str()
(和print
)给出了人类(最终用户)可读的形式。
另请参阅:str() vs repr() functions in python 2.7.5也适用于python 3。
答案 1 :(得分:0)
import sys
sys.stdout.write("rotation: %d%%\t [note]"% 123)
这应该有效