If you use “ ‘ ” or ’ “ ‘, the inside quote will be considered quote. Otherwise, you need use \
12345678910
>>>'eggs''spam eggs'>>>'doesn\'t'# use \' to represent single quote because this is ' ' '"doesn't:>>>'"Yes," he said.'# you don't need \" because it's ' " ''"Yes," he said.'>>>"\"Yes,\" he said."# you have to use \" for ", because this is " " "'"Yes," he said.'>>>'"Isn\'t," she said,''"Isn\'t," she said.'
print() will handle ‘\’ as special character
123456789
>>>'"Isn\'t," she said.''"Isn\'t," she said.'>>>print('"Isn'\t,"she said.')"Isn't,"shesaid.# \ will not be displayed>>>s='First line, \nSecond line.''First line, \nSecond line.'>>>print(s)Firstline,Secondline.
If you want python accpet \, you need to add r before the first quote
String can be indexed starting from 0. string[0] is also string type
12345
>>>word="Python">>>word[0]'P'>>>word[5]'n'
Indices may also be negative numbers which start counting from the right, negative indices starts from -1
123456
>>>word[-1]'n'>>>word[-2]'o'>>>word[-6]'P'
Slicing is supported in string. We can get substring by slicing
1234567891011
>>>word='Python'>>>word[0:2]# get characters [0,2)'Py'>>>word[:2]'Py'>>>word[4:]# get characters [4,length]'on'>>>word[-2:]'on'>>>word[:2]+word[2:]'Python'
Attempting to use a index that is too large will result in error