String assignment using '
or "
:
>>> s = 'Perschon.com' >>> s2 = "Perschon.com" >>> s == s2
TrueString is can be treated as a list of characters:
>>> s[0]
'E'
>>> s[3:6]
'Mem'Search for substring:
>>> x = 'Perschon Python Tutorial' >>> 'P'in x
True
>>> 'x'not in x
TrueString concatenation use
"+"
, "+="
operators or join()
Method.
>>> str = "python" >>> str += " tutorial" >>> str
"python tutorial"
>>> str2 = "Perschon" >>> str3 = " -- ".join((str,str2)) >>> str3
"python tutorial -- Perschon"
>>> str = "python" >>> str2 = " tutorial" >>> str3 = str + " " + str2 >>> str3
'python tutorial'
split()
method divide a string based on specified separator.
>>> x = 'Perschon Python Tutorial' >>> x.split('th')
['Perschon Py', 'on Tutorial']
>>> x.split('o')
['EndMem', ' Pyth', 'n Tut', 'rial']
>>> x.split('o',1)
['EndMem', ' Python Tutorial']String formatting for print:
>>> print ("%s is No. %d" % ("perschon.com", 1))
perschon.com is No. 1Python string format symbol list: