Original link:
http://www.cnblogs.com/pinpin/p/9896092.html
python string type is a built-in type, without having to install
Methods / properties | Explanation |
capitalize() | The first character of the string to uppercase |
casefold() | All the characters in the entire string to lowercase |
center(width) | String center, and padded with spaces to the width of the new string length |
count(sub[,start[,end]]) | Returns the number of sub occurring inside the string, start and end parameters indicates a range, optional. |
encode(encoding='utf-8', errors='strict') | To encoding specified encoding format for encoding strings. |
endswith(sub[,start[,end]]) | Check whether the string sub substring end, a return True, otherwise False. parameter indicates the start and end range, optional. |
expandtabs([tabsize=8]) | The tab character string (\ t) are converted to spaces, if not specified, the default is the number of spaces tabsize = 8. |
find(sub[,start[,end]]) | Detecting whether the sub contained in the string, if the index value is returned, otherwise -1, start and end parameters indicates a range, optional. |
index(sub[,start[,end]]) | Like find methods, but not if the sub string will produce an exception. |
isalnum () | If there is at least one character string and all the characters are letters or numbers it returns True, otherwise False. |
Islf () | If there is at least one character string and all the characters are the letters return True, otherwise False. |
isdecimal() | If the string contains only decimal digits returns True, otherwise False. |
isdigit () | If the string contains only digit returns True, otherwise False. |
islower() | These characters If the string contains at least one of alphanumeric characters, and all lowercase, True is returned, otherwise it returns False. |
isnumeric() | If the string contains only numeric characters, it returns True, otherwise False. |
isspace() | If the string contains only spaces, returns True, otherwise False. |
istitl A () | If the string is the title (all the words are in uppercase began rest of the letters are in lower case), then returns True, otherwise False. |
isupper() | If the string contains at least one case sensitive characters, and these characters are uppercase, True is returned, otherwise it returns False. |
join(sub) | String as a separator interposed between all of the characters in the sub. |
light (width) | Returns a string left-aligned and padded with spaces to the width of the length of the new string. |
lower() | Convert a string to all uppercase characters to lowercase. |
lstrip() | Remove all of the strings of spaces left |
partition(sub) | Found sub substring, the string into a 3-tuple (pre_sub, sub, fol_sub), if the string is not included in the sub returns ( 'original string', '', '') |
replace(old,new[,count]) | Replace the old sub-string to string new substring, if the count is specified, alternatively no more than count times. |
rfind(sub[,start[,end]]) | Similar to the find () method, but is beginning to find the right. |
rindex(sub[,start[,end]]) | Similar to the index () method, but starting from the right. |
rjust(width) | Returns a string right justified and padded with spaces to the width of the length of the new string. |
rpartition(sub) | Similar to the partition () method, but is beginning to find the right. |
rstrip() | Remove spaces at the end of the string. |
split(sep=None, maxsplit=-1) | The list is not the default parameters spliced substring after the separator to space string sections, if maxsplit parameters set, only the partition maxsplit substrings, returns slice. |
split lines (([notch ends])) | According to '\ n' separator, a return line contains the elements as a list, if keepends parameter is specified before keepends return line. |
startswith(prefix[,start[,end]]) | Check whether the string starts with prefix, it returns True, otherwise False. parameters may specify start and end range check, optional. |
strip([chars]) | Delete all strings front and back spaces, chars parameter can be customized character deleted, optional. |
swapcase() | Flip case string. |
title() | Returns the title (all the words are in uppercase start, the rest of the letters are lowercase) string. |
translate(table) | The rules table (may be made str.maketrans ( 'a', customized 'b')) of the character string conversion. |
upper() | Conversion string all lowercase characters to uppercase. |
zfill(width) | Returns a string of length to width, the original string is right-justified with zero-padded front. |
Examples of parts:
1 str1 = 'i love python! let\'s study it together!' 2 3 print(str1.capitalize()) #将第一个字符改为大写 4 #I love python! let's study it together! 5 6 print(str1.title()) #返回标题化(所有的单词都是以大写开始,其余字母均小写)的字符串。 7 #I Love Python! Let'S Study It Together! 8 9 print(str1.upper()) #转换字符串中的所有小写字符为大写。 10 #I LOVE PYTHON! LET'S STUDY IT TOGETHER! 11 12 print(str1.center(50)) #将字符串居中,并使用空格填充至长度 50 的新字符串 13 # i love python! let's study it together! 14 15 print(str1.isalpha()) #如果字符串至少有一个字符并且所有字符都是字母则返回 True,否则返回 False。 16 #False 17 #... ...
转载于:https://www.cnblogs.com/pinpin/p/9896092.html