Want to get a substring of a string in Python? Use the following python example code:
1 2 3 4 5 6 7 8 9 10 11 | >>> 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.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.