slice at : python code example
Example 1: slicing 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"
Example 2: python slice operator
string = 'string_text'
beginning = 0 # at what index the slice should start.
end = len(string) # at what index the slice should end.
step = 1 # how many characters the slice should go forward after each letter
new_string = string[beginning:end:step]
# some examples
a = 0
b = 3
c = 1
new_string = string[a:b:c] # will give you: str
# ____________________________________________
a = 2
b = len(string) - 2
c = 1
new_string = string[a:b:c] # will give you: ring_te