Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Write a 3 line Python Code that will take User Input String and give its Reverse as a Output

I want a Three Line Code
first Line should be string Input
second line should be the process in which sting is getting reverse
and third line should be output showing its reverse

and the Language used is Python

I have taken a input like = racecar
so i need output as = racecar

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

so the process of reversing the string should be of 1 line only..

>Solution :

Here you have what you requested:

a = input("")
b = a[::-1]
print(b)

The line a = input("") will ask the user an input and store it in the variable a as a string type.

The line b = a[::-1] will reverse the string and store the result in variable b.

The line print(b) will print result.

You can do it in one line with:

print(input("")[::-1])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading