# Slices
#Slice gets part of data in object [start position: End position (not included): Step]Qpstr ="Shandong Jacky"result= Qpstr[1:3: 1]#Dong ZhangPrint(Result)#Quick Pick up top tworesult = Qpstr[:2]Print(Result)#quickly take the latter tworesult = Qpstr[-2:]Print(Result)#get the entire string quicklyresult =qpstr[:]#quickly get string reversal stringresult = Qpstr[::-1]Print(Result)
# Find detects if STR is contained in MYSTR, or returns 1 if the index value is returned.
# mystr.find (str, start=0, End=len (mystr))
" ABC de " = Mystr.find ("a")# (specifies what to look for, start position, end position (not included))find = Mystr.find ("ABC", 0, 1)print(Find)
# Index is the same as the Find () method, except if STR does not report an exception in MyStr
# Mystr.index (str, start=0, End=len (mystr))
index = Mystr.index ("ABC", 0, Len (mystr))print(index)
# Count Returns the number of occurrences of str between start and end in MyStr
# Mystr.count (str, start=0, End=len (mystr))
Count = Mystr.count ("a", 0, Len (mystr))print(count)
# Replace replaces str1 in mystr with STR2 if Count is specified, no more than count times
# Mystr.replace (str1, str2, Mystr.count (STR1))
Replace = Mystr.replace ("C""a", Mystr.count ("A "))print(replace)
# Split slices mystr with str, if Maxsplit has a specified value, only maxsplit substrings are delimited
# Mystr.split (str= "", 2)
Split = Mystr.split ("", 2) # result array format print(split)
Python basics: Common operations for strings