1. Split string
str.split (sep, maxsplit) # (delimiter, several times)
2. Merge string
= str2 String .join (Iterable) str2 = # ' @ ' .join (List1) is a list List1 #
3. Retrieve string
- count()
- find()
- start with ()
- endwith()
4. The letter case change
- lower()
- upper()
5. Remove the string spaces and special characters
- strip () # remove the string around the spaces and special characters
- lstrip () # remove the left side ....
- rstrip () # remove the right of ...
6. The format string
- use%
' % [-] [+] [0] [m] formatting characters [n-.] ' % A # - an optional parameter, left-justified, unsigned positive number in front of, # + optional parameters, right-aligned, a positive number plus + sign in front of # 0 optional parameter by aligned front unsigned positive number, the space is filled with 0, and m is generally used with # optional parameter m, the parameter indicates occupy # .n optional parameters, the decimal places bits # formatting characters for specifying the type of % s% d% f% e %%
- Use Format ()
Print ( ' the result is: {}. 2F :. ' .format (A), ' and ' , ' {:} .5f ' .format (B)) Print ( ' the result is: {}. 2F :. ' .format ( A) + ' and ' + ' {:} .5f ' .format (B)) # can be
7. encoding and decoding python default in UTF-8
= STR ' black ~ tao Sucker ' AA = str.encode () Print (AA) BB = aa.decode () Print (BB)
8. Regular