Sco*_*721 6 python string indexing quotes
假设我有一个字符串变量
temp = 'I need to "leave" this place'
Run Code Online (Sandbox Code Playgroud)
我如何能够使用 temp.index() 来查找引号("") 的开始和结束位置?
我会使用查找方法。
start_pt = temp.find("\"")
end_pt = temp.find("\"", start_pt + 1) # add one to skip the opening "
quote = temp[start_pt + 1: end_pt]
>>> print start_pt, end_pt, quote
10, 16, 'leave'
Run Code Online (Sandbox Code Playgroud)