Python slicing is about obtaining a sub-string from the given string by slicing it respectively from start to end.
Python slicing can be done in two ways.
- slice() Constructor
- Extending Indexing
slice() constructor creates a slice object representing the set of indices specified by range(start, stop, step).
- slice(start, stop, step)
start: Starting index where the slicing of object starts.
stop: Ending index where the slicing of object stops.
step: It is an optional argument that determines the increment between each index for slicing.
Return Type: Returns a sliced object containing elements in the given range only.
Index tracker for positive and negative index:
Negative comes into considers when tracking the string in reverse.
String slicing AST SR GITA
In Python, indexing syntax can be used as a substitute for the slice object. This is an easy and convenient way to slice a string both syntax wise and execution wise.
start, end and step have the same mechanism as
AST SR GITA Reverse String GNIRTSA
Note: To know more about strings click here.
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Reverse Slicing of given string
- String slicing in Python to rotate a string
- Python | Reverse Interval Slicing String
- Python | Reverse Incremental String Slicing
- Python | Get the substring from given string using list slicing
- Python | K elements Slicing
- Python - Convert 2D list to 3D at K slicing
- Python | Custom slicing in List
- Python | Custom List slicing Sum
- Python | Variable list slicing
- Python List Comprehension and Slicing
- Slicing range() function in Python
- Interesting facts about strings in Python | Set 2 (Slicing)
- Python Slicing | Extract ‘k’ bits from a given position
- Python | Alternate range slicing in list
- Python Slicing | Reverse an array in groups of given size
- Basic Slicing and Advanced Indexing in NumPy Python
- Program to cyclically rotate an array by one in Python | List Slicing
- Python | Slicing list from Kth element to last element
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.