string slicing in python code example
Example 1: 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 2: get a slice of string in python
string = "something"
slice = string[0:3]
slice = string[0:-3]
slice = string[3:]
slice = string[:3]
slice = string[::2]
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: slicing in python
word = "Example"
sliced_word = word[:3]
second_sliced_word = word[3:]
Example 5: string slicing in python 3 arguments
>>> range(10)[::2]
[0, 2, 4, 6, 8]
Example 6: how to slice a string in python
a = 'hello'
print(a[1:2])