Wednesday, November 6, 2019

reverse the given string using slice operator


a=input("Enter some string::")
print(a[::-1])

output:
Enter some string::anil durgam
magrud lina


method 2:
 using inbuilt functions


a=input("Enter some string::")
for x in reversed(a):
    print(x)

output:
Enter some string::anil durgam
m
a
g
r
u
d

l
i
n
a

join method

a=input("Enter some string::")
print(''.join(reversed(a)))

output:
Enter some string::anil
lina


without new line of the reversed string

a=input("Enter some string::")
for x in reversed(a):
    print(x,end='')

output:
Enter some string::anil
lina

No comments:

Post a Comment

python class topic video