There are usually multiple characters in a string in Python, how do I intercept it?
Example: name = ' My name is jockey '
We first numbered this string, starting with 0:
1. Print a character
>>> print (name[0])
M
>>> print (name[11])
J
2. Print one of the characters
If the side of the colon is empty to identify the end, the value is followed by the left closed right open principle, that is: [)
>>> print (name[3:14])
Name is JOC
>>> print (name[6:])
E is jockey
>>> print (name[:16])
My name is Jocke
>>> print (name[:17])
My name is jockey
3. Reverse Intercept
The reverse intercept is sorted from right to left, starting with 1 instead of starting at 0.
Segment printing or left-to-right open, consistent with positive alignment
>>> print (name[-1])
Y
>>> print (name[-6])
J
>>> print (name[-9:-1])
Is Jocke
Draw on an interesting exercise from elsewhere:
"Find the Devil in your friend."
Word = ' friends '
Find_the_evil_in_your_friends = word[0] + word[2:4] + word[-3:-1]
Print (Find_the_evil_in_your_friends)
Execution Result: Fiend Devil
Interception of Python strings