Python line breaks

I took integer input and tried changing it to Python, but to no avail! I changed it to a string but still can't. Is there any way to cancel it? Is there a built-in function?

I cannot convert an integer to a list, so I cannot apply the inverse function.

+7
python
source share
3 answers

You can use the slicing operator to change the string:

s = "hello, world" s = s[::-1] print s # prints "dlrow ,olleh" 

To convert an integer to a string, reverse it and convert back to an integer, you can do:

 x = 314159 x = int(str(x)[::-1]) print x # prints 951413 
+30
source share

the code:

 >>> n = 1234 >>> print str(n)[::-1] 4321 
+4
source share
 >>> int(''.join(reversed(str(12345)))) 54321 
+2
source share

All Articles