1# strings are immutable in Python,
2# we have to create a new string which
3# includes the value at the desired index
4
5s = s[:index] + newstring + s[index + 1:]
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
1mystring = 'hello, world'
2
3mylist = string1.split(', ') #output => ['hello', 'world']
4
5myjoin1 = ', '.join(mylist) #output => 'hello, world'
6myjoin2 = ' '.join(mylist) #output => 'hello world'
7myjoin3 = ','.join(mylist) #output => 'hello,world'
1sentence = 'Python programming is fun.'
2
3result = sentence.index('is fun')
4print("Substring 'is fun':", result)
5
6result = sentence.index('Java')
7print("Substring 'Java':", result)