Python strings Function


String assignment using ' or ":

>>> s = 'EndMemo.com'
>>> s2 = "EndMemo.com"
>>> s == s2
True

String is can be treated as a list of characters:
>>> s[0]
'E'
>>> s[3:6]
'Mem'

Search for substring:
>>> x = 'EndMemo Python Tutorial'
>>> 'P' in x
True
>>> 'x' not in x
True

String concatenation use "+", "+=" operators or join() Method.
>>> str = "python"
>>> str += " tutorial"
>>> str
"python tutorial"

>>> str2 = "EndMemo"
>>> str3 = " -- ".join((str,str2))
>>> str3
"python tutorial -- EndMemo"


>>> str = "python"
>>> str2 = " tutorial"
>>> str3 = str + " " + str2
>>> str3
'python tutorial'

split() method divide a string based on specified separator.
>>> x = 'EndMemo Python Tutorial'
>>> x.split('th')
['EndMemo 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" % ("endmemo.com", 1))
endmemo.com is No. 1

Python string format symbol list:
SymbolDescription
%ccharacter
%sstring
%dsigned decimal integer
%iinteger
%uunsigned decimal integer
%ooctal integer
%ffloating number
%eexponential notation with lowercase e
%Eexponential notation with uppercase E
%xhexadecimal integer in lowercase
%Xhexadecimal integer in uppercase