Monday, 29 August 2016

Python program to reverse a string using slice operation

A simple python program to reverse a string. Here we use slice operation to reverse a string.

Syntax : str[begin:end:step]. So by leaving begin and end, and giving a step of -1, it reverses a string.

Refer below for screenshot and program,




PROGRAM :

input_string = str(input('Enter any string : '))
print("Reversed String is : " + input_string[::-1])


OUTPUT :  

Python - String reverse using slice operation












No comments:

Post a Comment