1
t = ("rotation: %d%%\t [note]"% 123)
in jupyter notebook when you type t and run cell
output: rotation: 123%\t [note]

I want to get result is follow here:

output: rotation: 123% [note]

2 Answers2

1

This is a manifestation of jupyter notebook. When using str, which print uses by default, we get

rotation: 123%   [note]

But when you type t into interactive python then repr() is used instead. It can be reproduced quite easily using any interactive python:

>>> t = ("rotation: %d%%\t [note]"% 123)
>>> t
'rotation: 123%\t [note]'
>>> print(t)
rotation: 123%   [note]

The difference is that repr() gives a representation of the object such that it can be recreated by code and is most useful for debugging. str() (and print) gives a human (end-user) readable form.

See also: str() vs repr() functions in python 2.7.5 which also applies to python 3.

cdarke
  • 42,728
  • 8
  • 80
  • 84
0
import sys
sys.stdout.write("rotation: %d%%\t [note]"% 123)

This should work

Yashik
  • 391
  • 5
  • 17