>>> 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.
More Related Contents:
- find all possible combinations of letters in a string in python [duplicate]
- Does Python have a string ‘contains’ substring method?
- Why does substring slicing with index out of range work?
- How to extract the substring between two markers?
- How to get a string after a specific substring?
- Find the nth occurrence of substring in a string
- How To Get All The Contiguous Substrings Of A String In Python?
- Replace nth occurrence of substring in string
- Find substring in string but only if whole words?
- Python: How to check a string for substrings from a list? [duplicate]
- Python: Find a substring in a string and returning the index of the substring
- How do I check if a given Python string is a substring of another one? [duplicate]
- Convert bytes to a string
- Best way to replace multiple characters in a string?
- How to check if a string in Python is in ASCII?
- TypeError: not all arguments converted during string formatting python
- How do I append one string to another in Python?
- add a string prefix to each value in a string column using Pandas
- How can I split and parse a string in Python?
- How can strings be concatenated?
- Longest common substring from more than two strings
- Count consecutive characters
- How does my input not equal the answer?
- shuffle string in python
- Convert a columns of string to list in pandas
- What’s the difference between str.isdigit(), isnumeric() and isdecimal() in Python?
- Python: is using “..%(var)s..” % locals() a good practice?
- How does python startswith work?
- How can I match an exact word in a string?
- Fast string array – Cython