s = 'abcabc' s.upper() s.isupper() s.capitalize() s.index('b') s.index('z') s.find('b') s.find('z') s.count('c') s = s.replace('b','z') s = s.replace('b','z',1) t = 'abc def ghi' t.split(' ') output = ''.join(i for i in list1)
"ABCABC" False "Abc" 1 error 1 -1 2 "azcazc" "azcabc" ['abc', 'def', 'ghi']
String Slicing
s = 'abcd' s[0] s[-1] s[1:3] s[::-1]
a d bc dcba
Since strings are immutable, there is no method to replace an arbitrary character of a string (e.x. replacing the second 'o' in 'foo'). But we can use the following function (taken from here ):
def arbit_replace(s, i, c): return s[:i] + c + s[i + 1:] print arbit_replace('foo', 2, 'z')
foz