original link:http://www.faceye.net/search/144443.html
1. All standard sequence operations are used in strings, remembering that the strings are immutable.
2. String formatting: Token conversion specifier (%), if the string itself contains%, replace with percent.
3. String format Conversion flag:-Indicates left alignment, + means home plus minus sign before the value is converted, "" (white space character) to retain a space before the positive number, and 0 to indicate that the conversion value is not sufficient for 0 padding.
4. Find (str, begin_index, End_index): Returns the leftmost index where the substring is located, no return-1 found. Note that Begin_index and End_index are left closed right;
5. Join (SEQ): Adding elements to the queue
>>> dirs= ', ' usr ', ' bin ', ' env '
>>> '/'. Join (dirs)
'/usr/bin/env '
>>> dirs
(', ' usr ', ' bin ', ' env ')
6. Lower ()/upper ()/islower ()/isupper (): for string case processing;
7. Replace (): Returns the string after a substring has been replaced;
8. Split (): separates strings into sequences, join () inverse method, default to Space/tab/change behavior delimiter;
9. Strip (x): Remove the set character X on either side of the string, and remove the space by default
>>> ' * * * SPAM * for * everyone!!! '. Strip ('!* ')
' SPAM * for * everyone '
Translate (): Similar to replace (), but can handle only a single character, multiple substitutions may be made at the same time, the second parameter specifies the character to be deleted, and it needs to be mated with the Maketrans function:
>>> from string import Maketrans
>>> Table=maketrans (' cs ', ' KZ ')
>>> ' This was an incredible test '. Translate (table, ')
' Thizizaninkredibletezt '
11. Other commonly used string methods:
S.capitalize () #首字母大写
S.istitle () #S是否是首字母大写的
S.isupper () #S中的字母是否全是大写
S.islower () #S中的字母是否全是小写
S.lstrip () #去掉字符串的左边空格
S.rstrip () #去掉字符串的右边空格
S.startwith (Prefix[,start[,end]) #是否以prefix开头
S.endwith (Suffix[,start[,end]) #以suffix结尾
S.index (substr, [Start, [end]]) is the same #与find (), but returns a run-time error when there is no substr in S
S.rindex (substr, [Start, [end]])
S.rfind (substr, [Start, [end]]) #从右边算起的第一次出现的substr的首字母标号, returns 1 if there is no substr in S
S.count (substr, [Start, [end]]) #计算substr在S中出现的次数
Several common functions of the string module:
String.atoi (S[,base]) #base默认为10, if 0, then s can be 012 or 0x23 This form of string, if it is 16 then s can only be 0x23 or 0x12 this form of string
String.atol (S[,base]) #转成long
String.atof (S[,base]) #转成float
original link:http://www.faceye.net/search/144443.html
Basic Python Tutorial---reading notes three