How To/python/

# -*- coding: utf-8 -*-
 
"""
string.find(string text) -> int
 
[en]
Return position of first occurence of txt in string.
To find last occurence of char use string.rfind()
Search is case sensitive.
Returns -1 when not found.
 
[pl]
Zwraca pozycję pierwszego wystąpienia ciągu txt w ciągu string.
Aby znaleźć ostanie wystąpienie użyj string.rfind()
Wyszukiwanie jest wrażliwe na wielkość liter.
Zwraca -1 jeśli ciąg nie został znaleziony.
"""
 
text = "Hello world"
 
print text.find("o")
#4
 
print text.find("llo")
#2
 
print text.find("x")
#-1
 
print text.find("W")
#-1
 
 
""" And little trick """
""" You can use 'in' operator to perform boolean test """
 
s = 'my long string'
 
print 'lo' in s
#True
 
print 'xx' in s
#False