How to reverse a string in python

Amansingh Javatpoint
1 min readMay 22, 2021

A Brief About Strings-

  1. The String is a data type in Python that has a sequence of characters. This series of characters are represented in single, double or triple quotes. Python has a built-in string class called ‘str’.

For example-

Name=’Darcy’

Nationality=” British”

Message= “Hello World”

  • The characters of strings can be accessed using the indexes. The expression [ ] in brackets is called an index.

For example-

message = “TENET”

The characters of this string can be accessed as-

message [0] = T

message [1] = E

message [2] = N

message [3] = E

message [4] = T

  • They are immutable which means they cannot be changed. A new string is created when we try to change or modify the existing string variable. Using id(), we can get the memory addresses of objects.
  • The feature of slicing present in strings can help us to fetch the characters of our choice. The syntax of slice operation is s[start:end].

Start specifies the beginning index of the substring.

End specifies the last character index of the substring.

a=’CORSICA’ OUTPUT

print(a[1:5]) ORSI

print(a[1:]) ORSICA

print(a[:6]) CORSIC

  • Regular Expressions are an influential tool for different kinds of manipulation of our strings. They can be accessed using the re module.

--

--