python string slices code example
Example 1: python string indexing
str = 'codegrepper'
print(str[:])
print(str[::])
print(str[5:])
print(str[:8])
print(str[::2])
print(str[2:8])
print(str[2:8:2])
print(str[::-1])
print(str[::-3])
print(str[8:3:-1])
Example 2: python slice string
name = "dx4iot"
print(name[0:])
print(name[0:3])
print(name[::-1])
print(name[0:6:2])
print(name[-4:-1])
Example 3: python string slicing
my_string = "Hey, This is a sample text"
print(my_string[2:])
print(my_string[2:7])
print(my_string[2::2])
print(my_string[::-1])
Example 4: Python - Slicing Strings
b = "Hello, World!"
print(b[2:5])