- 去掉字符串的开头和结尾——函数strip()
s = " hello world "
s = s.strip()
输出:
hello world
2.搜索字符串中的空格并返回相应下标
s = " hello world "
a = [i for i,x in enumerate(s) if x == ' ']
输出:
[0, 1, 7, 13, 14]
注意enumerate和index的区别
3. 在python中空格的表示——引号+空格+引号
s = " hello world "
s = s.strip()
输出:
hello world
2.搜索字符串中的空格并返回相应下标
s = " hello world "
a = [i for i,x in enumerate(s) if x == ' ']
输出:
[0, 1, 7, 13, 14]
注意enumerate和index的区别
3. 在python中空格的表示——引号+空格+引号