1str = 'codegrepper'
2# str[start:end:step]
3#by default: start = 0, end = len(str), step = 1
4print(str[:]) #codegrepper
5print(str[::]) #codegrepper
6print(str[5:]) #repper
7print(str[:8]) #codegrep
8print(str[::2]) #cdgepr
9print(str[2:8]) #degrep
10print(str[2:8:2]) #dge
11#step < 0 : reverse
12print(str[::-1]) #reppergedoc
13print(str[::-3]) #rpgo
14# str[start:end:-1] means start from the end, go backward and stop at start
15print(str[8:3:-1]) #pperg
1my_string = "Hello World!"
2
3my_string.index("l") # outputs 2
4# this method only outputs the index of the first "l" value in the string/list
1# vowels list
2vowels = ['a', 'e', 'i', 'o', 'i', 'u']
3
4# index of 'e' in vowels
5index = vowels.index('e')
6print('The index of e:', index)
7
8# element 'i' is searched
9# index of the first 'i' is returned
10index = vowels.index('i')
11
12print('The index of i:', index)
1# Python is a 0-based indexing language, meanign all indices start from 0
2list1 = ["Python", "Is", "A", "0", "Based", "Indexing", "language"]
3print(list1[0]) # Prints Python.... the element on index 0, 1 in human counting
1# IndexError comes because you are trying to get the item that don't exists
2# it means if you ant to get the numbers
3
4numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9 10]
5length_of_numbers = len(numbers)
6
7printnumbers(length_of_numbers) # raises IndexError because the len()
8# function starts counting from 1 but the index sarts counting from 0