>>> x = "Hello World!"
>>> x[2:]
'llo World!'
>>> x[:2]
'He'
>>> x[:-2]
'Hello Worl'
>>> x[-2:]
'd!'
>>> x[2:-2]
'llo Worl'

Python calls this concept "slicing" and it works on more than just strings. Take a look here for a comprehensive introduction.

Answer from Paolo Bergantino on Stack Overflow
๐ŸŒ
InterviewQs
interviewqs.com โ€บ ddi-code-snippets โ€บ substring-python
Slice a string in python (right, left, mid equivalents) - InterviewQs
A step-by-step Python code example that shows how to slice a string (right, left, mid equivalents). Provided by InterviewQs, a mailing list for coding and data interview problems.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ left string in python
How to Get Parts of a String in Python | Delft Stack
February 15, 2024 - As you can see from the above example, by telling Python that the starting point is 0 and the ending point is 6, we can get the specific part of the string using the slicing method. We got the left part of the string.
๐ŸŒ
Trymito
trymito.io โ€บ excel-to-python โ€บ functions โ€บ text โ€บ LEFT
Excel to Python: LEFT Function - A Complete Guide | Mito
The LEFT function in Excel returns the first N characters in a text string, based on the number of characters you specify. ... Get answers from your data, not syntax errors. Download the Mito AI analyst ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-substring-a-string-in-python
How to Substring a String in Python
January 3, 2020 - Python offers many ways to substring a string. This is often called "slicing". Here is the syntax: string[start:end:step] Where, start: The starting index of the substring. The character at this index is included in the substring. If start is not in...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_ref_string.asp
Python String Methods
Python has a set of built-in methods that you can use on strings.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-right-and-left-shift-characters-in-string
Python - Right and Left Shift characters in String - GeeksforGeeks
July 12, 2025 - Positive values for rotate perform right shifts, while negative values perform left shifts. ... The result is obtained by converting the rotated deque back into a string.
๐ŸŒ
Google
developers.google.com โ€บ google for education โ€บ python โ€บ python strings
Python Strings | Python Education | Google for Developers
The % operator takes a printf-type format string on the left (%d int, %s string, %f/%g floating point), and the matching values in a tuple on the right (a tuple is made of values separated by commas, typically grouped ...
๐ŸŒ
Stanford CS
cs.stanford.edu โ€บ people โ€บ nick โ€บ py โ€บ python-string.html
Python Strings
Negative numbers also work within [ ] and slices: -1 is the last char in the string, and -2 is the next to last char, and so on. So for example with s = 'Python', s[-1] is 'n' and s[-2] is 'o'. This is convenient when you want to refer chars near the end of the string, and it works in slices too.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ substrings
Python | Substrings | Codecademy
June 18, 2025 - A Python substring is a sequence of characters that are part of an original string. In Python, substrings can be obtained by using the slicing feature on a string variable.
๐ŸŒ
Databricks
docs.databricks.com โ€บ pyspark reference โ€บ functions โ€บ left
left | Databricks on AWS
June 4, 2026 - Returns the leftmost len(len can be string type) characters from the string str, if len is less or equal than 0 the result is an empty string. For the corresponding Databricks SQL function, see left function.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Right-justify, Center, Left-justify Strings and Numbers in Python | note.nkmk.me
May 18, 2023 - Use the rjust(), center(), or ljust() methods to right-justify, center, or left-justify strings str in Python. You can convert numbers (int and float) to strings using str() and apply these methods. R ...
๐ŸŒ
ListenData
listendata.com โ€บ home โ€บ python
String Functions in Python with Examples
The table below shows many common string functions in Python along with their descriptions and their equivalent functions in MS Excel. If you are intermediate MS Excel users, you must have used LEFT, RIGHT and MID Functions.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-substring-a-string-in-python
How to Substring a String in Python - GeeksforGeeks
August 9, 2024 - A String is a collection of characters arranged in a particular order. A portion of a string is known as a substring. For instance, suppose we have the string "GeeksForGeeks". In that case, some of its substrings are "Geeks", "For", "eeks", and so on. This article will discuss how to substring a string in Python.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_string_ljust.asp
Python String ljust() Method
Note: In the result, there are actually 14 whitespaces to the right of the word banana. The ljust() method will left align the string, using a specified character (space is default) as the fill character.