Given a string, write a Python program to get the substring from given string using list slicing. Let’s try to get this using different examples.
In this example, we will see how to take a substring from the end or from starting of string.
initial_strings : xbzefdgstb print resultant substring from start xb print resultant substring from end efdgstb
In this example, we will see how to create a string by taking characters from the certain positional gap.
initial_strings : xbzefdgstb print resultant substring from start xzfgt print resultant substring from end xegb
In this example, we are considering both cases of taking string from the middle with some positional gap between characters.
initial_strings : xbzefdgstb print resultant substring zfg
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- String slicing in Python to check if a string can become empty by recursive deletion
- String slicing in Python to rotate a string
- Python | Reverse Slicing of given string
- Program to cyclically rotate an array by one in Python | List Slicing
- Python | Slicing list from Kth element to last element
- Python | Variable list slicing
- Python | Alternate range slicing in list
- Python | Custom slicing in List
- Python | Custom List slicing Sum
- Python - Convert 2D list to 3D at K slicing
- Python List Slicing
- Python List Comprehension and Slicing
- String Slicing in Python
- Python | Reverse Interval Slicing String
- Python | Reverse Incremental String Slicing
- Python Slicing | Reverse an array in groups of given size
- Python Slicing | Extract ‘k’ bits from a given position
- Python - Filter the List of String whose index in second List contaons the given Substring
- Data Slicing using PyQtGraph
- Basic Slicing and Advanced Indexing in NumPy Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.