python3字符串的常见操作
1、find检测str是否包含在mystr,如果是返回开始的索引值,否则返回-1 In [ 5 ] : mystr = 'hello world itcast and hahaitcast' In [ 6 ] : mystr . find ( 'world' ) Out [ 6 ] : 6 In [ 7 ] : mystr . find ( 'heihei' ) Out [ 7 ] : - 1 2、index和find一样只不过,str不在mystr中会报一个异常 In [ 8 ] : mystr . index ( 'itcast' ) Out [ 8 ] : 12 In [ 9 ] : mystr . index ( 'heihei' ) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ValueError Traceback ( most recent call last ) < ipython - input - 9 - 2cd231cae32a > in < module > ( ) - - - - > 1 mystr .