这里会显示出您选择的修订版和当前版本之间的差别。
— |
note:spoony:python判断字符串是否包含另一字符串的方法 [2016/12/27 23:46] (当前版本) Spoony 创建 |
||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== Python判断字符串是否包含另一字符串的方法 ====== | ||
+ | <code> | ||
+ | site = '123' | ||
+ | if "12" in site: | ||
+ | print('site contains 12') | ||
+ | |||
+ | s = "This be a string" | ||
+ | if s.find("is") == -1: | ||
+ | print "No 'is' here!" | ||
+ | else: | ||
+ | print "Found 'is' in the string." | ||
+ | |||
+ | contains = 'abcde'.find('bcd') >= 0 | ||
+ | |||
+ | |||
+ | contains = 'abcde'.count('bcd') > 0 | ||
+ | </code> |