How to reverse a string in Python using slicing operator

0 votes

Hi Guys,

I am new to the python language. I want to perform the reverse of a string using a slicing operator. How can I do that?

Aug 16, 2020 in Python by akhtar
• 38,170 points
622 views

1 answer to this question.

0 votes

Hi@akhtar,

Strings can be reversed using slicing. To reverse a string, we simply create a slice that starts with the length of the string and ends at index 0. The slice statement means start at string length, end at position 0, move with the step -1.

str="Python"
stringlength=len(str)
slicedString=str[stringlength::-1]
print (slicedString)
answered Aug 16, 2020 by MD
• 95,060 points

Related Questions In Python

0 votes
1 answer

How to check if a substring is present in a string using Python?

To check if the substring exists in ...READ MORE

answered May 9, 2019 in Python by Sharan
285 views
+1 vote
1 answer

How to check if a string is in a file, using python?

Hi, Try the below given code: with open('myfile.txt') as ...READ MORE

answered Jul 4, 2019 in Python by Shabnam
• 930 points
436 views
+1 vote
2 answers

How to print first character of each word in upper case of a string in Python

class Solution:     def firstAlphabet(self, s):             self.s=s              k=''              k=k+s[0]              for i in range(len(s)):                     if ...READ MORE

answered Oct 28, 2020 in Python by Anurag
6,497 views
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,416 views
0 votes
1 answer

Removing surrounding whitespace

Try the strip() function:  s = s.strip() If you ...READ MORE

answered May 4, 2018 in Python by Nietzsche's daemon
• 4,260 points
142 views
0 votes
1 answer

How to transfer multiple lines in a file using python?

Hi@akhtar, I don't know it will help you ...READ MORE

answered Mar 31, 2020 in Python by MD
• 95,060 points
165 views
0 votes
1 answer

How to crop face from a photo using cv2 in python?

Hi@akhtar, You can do this task using cv2 ...READ MORE

answered Apr 9, 2020 in Python by MD
• 95,060 points
139 views