1.字符串索引

(1)index()索引函数

  1. a = 'abcdefgh'
  2. a.index(str) #索引str

当索引字符串可以被索引到时,返回索引位置,否则报错。

(2)find()索引函数

  1. a = 'abcdefgh'
  2. a.find(str) #索引str

当索引的字符串可以被索引到时,返回索引位置,否则返回”-1”。

2.字符串和ASCII的转换

(1)字符→ASCII

  1. ord('字符')

(2)ASCII→字符

  1. chr('ASCII')