查找特定字符串

时间:2013-03-23 14:05:43

标签: python string character

我有

形式的数据
str = '"A,B,C,Be,F,Sa,Su"' # where str[1]='M' and str[2]=','

我想找if "mystring" in str:。其中mystring是M,T,W或Th等。

但是,我只想要特定的字符串。即if "S" in str:输出应为无。并且if "B" in str:应该只是'B'而不是'Be'

1 个答案:

答案 0 :(得分:3)

>>> text = '"A,B,C,Be,F,Sa,Su"'
>>> 'A' in text.strip('"').split(',')
True
>>> 'S' in text.strip('"').split(',')
False
相关问题