#SLICING
Obi William
Experienced Full-Stack Engr with over 5 yrs of expertise in Python | C | Java | JavaScript | Typescript | React | HTML | CSS | Flask | Django | Node.js | MYSQL | MongoDB | Redis | AWS | CI/CD | REST API | DevOps.
a = "Hello World!"
print(a[::-1])
"""
!dlroW olleH
"""
Slicing is a feature in Python that relies on indexing to allow users to access a subset of a sequence. An index is simply the position of an element in a sequence. If the sequence type is mutable, you can use slicing to extract and modify data.?
Note: We may also use slicing on an immutable sequence, but trying to modify the slice will raise a TypeError.?
The format in which slices are implemented is: sequence[start:stop:step]. If no values are specified in the start, stop, and step parameters, then the sequence will implement the defaults. The defaults are:?
When provided with sequence[start:stop] the elements returned will be from the starting index up to the stop?-?1 (the stop index is not included).?
We can also pass negative indices, which may be used to reverse the sequence. For example, in a list of 4 elements, the 0th index is also the -4 index, and the last index is also -1. In the example code above, this knowledge was applied to the step parameter of the sequence. Consequently, the string was printed backward, starting from the end of the sequence to index 0.??