Python String Reversed
In Python Programming tutorials, By accessing characters from a string, we can also reverse strings in Python Programming. We can Reverse a string by using String slicing method.
In this example, we will reverse a string by accessing the index. We did not specify the first two parts of the slice indicating that we are considering the whole string, from the start index to the last index.
#Program to reverse a string
gfg = "w3wiki"
print(gfg[::-1])
Output:
skeegrofskeeg
BuildIn Reverse Function in Python
We can also reverse a string by using built-in join and reversed functions, and passing the string as the parameter to the reversed() function.
# Program to reverse a string
gfg = "w3wiki"
# Reverse the string using reversed and join function
gfg = "".join(reversed(gfg))
print(gfg)
Output:
skeegrofskeeg
Python String
A String is a data structure in Python Programming that represents a sequence of characters. It is an immutable data type, meaning that once you have created a string, you cannot change it. Python String are used widely in many different applications, such as storing and manipulating text data, representing names, addresses, and other types of data that can be represented as text.
Table of Content
- What is a String in Python?
- Create a String in Python
- Accessing characters in Python String
- String Slicing
- Python String Reversed
- Deleting/Updating from a String
- Escape Sequencing in Python
- Python String Formatting
- Useful Python String Operations
- Python String constants
- Deprecated string functions
- FAQ’s on Python String