Python Slicing – How to get substring
What we call as substring in C/C++/Java/CSharp/VB is implemented by slicing in python.
Slicing works something like this:
name = ‘techiedrill’
Here, python treats the string as
0-t
1-e
2-c
4-h and so on…
So, to get a part of the original string, all that needs to be done is use the : symbol. This is called slicing.
first = name[:5] ===> first = ‘techie’
last = name[5:] ===> last = ‘drill’
middle = name[2:6] ===> middle = ‘chied’
This is simple inbuilt function !~!!!!