The next day learning - string method

Yesterday learned some strings of some commonly used methods, the system today to learn other ways to string

1、capitalize()

The first letter capitalized string, other letters to lower case. The difference between it and the title () is the first letter he would become a string of uppercase and lowercase letters in the other, while the title () is a capitalized string processing

 

 

 

 2、casefold() 

casefold () method is introduced Python3.3 later versions, and the effect  lower ()  methods are very similar, the string can be converted to all uppercase characters in lower case.

The difference is: lower () method only ASCII encoding, that is, 'A-Z' valid for other languages ​​(non-Chinese or English) in uppercase to lowercase situation can only be used casefold () method (online looking for). Probably no English at the time of the daily string of difference when time-sensitive case in other languages ​​can only use casefold (), commonly used or lower (), this method only understand, because I would not be in other languages.

 

 

 3、center()

This method returns a string of the original center, and padded with spaces to the width of the length of the new string. 

That this is a method to create a new string, the string is the original letter as a play on both sides for specific characters or spaces. The first parameter is the length of the new string, the second parameter is filled with both ends of the new string

 

 

 4、encode() 

encode () method  encoding  specified encoding format string. parameter errors can specify a different error handling scheme.

Is specified string specific coding format, temporarily did not expect what use are generally directly with utf-8,

5、endswith()

endsWith () method for determining whether the string ends with the specified suffix returns True if the end with the specified suffix, otherwise False. Optional parameter "start" and "end" for the start and end position of the search string.

I.e. detecting whether the trailing end of the string to an end of the string, or the end of a range specified string is a specific string.

 

 

 

 6、expandtabs()

The tab character strings in string into space, tab symbol default number of spaces is 8 

 

 

 

 7、find()

find () method detects whether a string contains the substring str, if the specified BEG (start) and end (END) range, it is checked whether contained within the specified range, if within the specified range if it contains the specified index value returned is index value starting position in the string. If the index does not contain the value -1.

And in the office to find the same, that is, within the designated area to find whether a string contains a string

 

 

 8、index() 

index () method comprising detecting whether the string str substring, if the specified BEG (start) and end (END) range, it is checked whether contained within a specified range, as in the method IND () method, but if str not in the string will report an exception. That is index () This method is more demanding, there is a return, there is no direct reported abnormal, so, feel or find () a number of easy to use.

 

 

 

 

 

 9, isalnum () 

 Whether isalnum () method for detecting a string of letters and numbers.

 

 

 

 

10, Islf ()

 Detecting whether a string consisting only of letters or text.

 

 

 11, isdigit () 

 Detecting whether a string consisting only of numbers.

 

 

 

 12、islower() 

Detecting whether the character string lowercase letters.

 

 

 

 13、isnumeric() 

Detecting whether a string consisting only of numbers, numbers may be: Unicode numbers, digital full-width (two-byte), Roman numerals, characters figures.

Similar index  ² with similar scores  ½ also belongs to digital.

14、isspace() 

Detecting whether the string consists of only blank characters.

15、 join() 

For the sequence element to specify a character string to generate a new connection.

 

 

 

 16 istitl A ()

Detect all words are spelled string is an uppercase first letter and other letters to lowercase.

17、isupper() 

Detecting whether strings all the letters are capitalized.

18, only ()

Length len (str) string to be tested

 

 

 

 19, light () 

ljust () method returns a string of the original left-aligned and padded with spaces to the new string length specified. If the length is less than the length of the string is returned in the original string.

A bit like center (), but he is at the end of filling r charge

 

 

 

 20, rjust () 

And ljust same, but he left the original string is filled, but if the specified length of the string is less than the length of the original string is returned

21、replace() 

replace () method of the string old (old string) replaced with new (new string), if the third argument max, max is not more than the replacement times.

 

 

 

 21、 rfind()

 rfind () returns the position of the last occurrence of the string, if there is no match or -1.

 

 

 

 22、rindex() 

Returns the position of the substring str in the last occurrence of the string, if there is no matching string will be reported exceptions, you can specify the optional parameter [beg: end] to set the interval to find.

 

 23、split() 

split () delimiter specified by the string sections, the second parameter if the value is specified num, num + 1 is divided into sub-strings.

 

 

 

 24、splitlines()

The splitlines () in rows ( '\ r', '\ r \ n', \ n ') separated returns a respective line as a list of elements, if the parameter keepends is False, no line breaks, if True, the retention newline.

25、startswith() 

For checking whether a string begins with a specified substring, if it returns True, otherwise False. If beg and end parameter specified value, it is checked in the specified range.

26、swapcase() 

Lowercase letters string for conversion.

 

 

 27、 translate()

(256 characters) characters in a string conversion table according to the parameters given in the table, be filtered into character  deletechars  parameter.

 

 

 28、zfill()

 A specified length of the original string right justified, padded with zeros in front.

 

 

 

 29、maketrans()

Making translation table

 

 

 

Guess you like

Origin www.cnblogs.com/xiaobai-yang/p/11605486.html