python3 sclining code example
Example 1: python string slicing
my_string = "Hey, This is a sample text"
print(my_string[2:]) #prints y, This is a sample text
print(my_string[2:7]) #prints y, Th excluding the last index
print(my_string[2::2]) #prints y hsi apetx
print(my_string[::-1]) #reverses the string => txet elpmas a si sihT ,yeH
Example 2: slice in python
word = "Example"
# Obtain the first 3 characters of "Example"
# E x a m p l e
# 0 1 2 3 4 5 6
# First 3 characters = "Exa"
sliced_word = word[:3] # Gives you "Exa"
# Everything after character #3 = "mple"
second_sliced_word = word[3:] # Gives you "mple"