Reputation: 31
I have been trying to convert an integer into a string. My codes are as follows:
n = 357
x = str(n)
print x
The problem is that online editors that I have tried are not printing the string as '357'. Instead the string is printed as 357. What have I been doing wrong?
Upvotes: 0
Views: 698
Reputation: 476493
You apparently want to print the representation of the string. Python has a builtin function repr(..)
for this:
n = 357
x = str(n)
print(repr(x))
The representation of a string is a list of characters between single or double quotes (double quotes if the string contains at least one single quote and no double quotes). Furthermore if there are escape sequences (like a new line), these are printed with a backslash (like \n
).
Upvotes: 5