find vs in operation in string python -


i need find pattern string , found can use in or find also. suggest me 1 better/fast on string. need not find index of pattern find can return index of pattern.

temp = "5.9" temp_1 = "1:5.9" >>> temp.find(":") -1 >>> if ":" not in temp:     print "no"  no  

use in , faster.

dh@d:~$ python -m timeit 'temp = "1:5.9";temp.find(":")' 10000000 loops, best of 3: 0.139 usec per loop dh@d:~$ python -m timeit 'temp = "1:5.9";":" in temp' 10000000 loops, best of 3: 0.0412 usec per loop 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -