A common method of string
1. Title (): Returns the title version of the string, that is, the first letter of the word and the remaining letter lowercase
2, Upper (): Returns all uppercase versions of the string, lower () returns all lowercase versions of the string
>>> s = "Hello, world"
>>> S.upper ()
' HELLO, World '
3, Swapcase (): Returns the version of the string case interchange
>>> s = "ABABCDEFABC"
>>> S.swapcase ()
' Ababcdefabc '
4, Isalnum (): Check whether all characters are alphanumeric
>>> s = "ABC 123"
>>> S.isalnum ()
False
>>> a = "ABC123ABC"
>>> A.isalnum ()
True
5, Isalpha () Check if there are only letters in the string; IsDigit () checks if all characters are numeric, islower () checks if all characters are lowercase, istitle () checks whether the string is a heading style; Isupper () Checks whether the string is uppercase for all characters
6. Split (): Splits any string, split () allows a parameter to be used to define what character string to split, default to ""
>>> s = "What:is:your:name"
>>> s.split (":")
[' What ', ' is ', ' your ', ' name ']
7. Join () linked multiple strings using the specified word, which requires a list of string elements as input and then links the string elements in the list
>>> "-". Join ("So, how can I do for you?"). Split ())
' So,-what-can-i-do-for-you? '
Second, the string stripping
1, strip (chars) is used to peel the characters specified in the end of the string, without specifying the parameters will be stripped off the end of the default space and line breaks
>>> a = "a bc\n"
>>> A.strip ()
' A BC '
2. Use Lstrip (chars) or Rstrip (chars) to split the string left or right
>>> s = "www.baidu.com"
>>> s.lstrip ("www.")
' Baidu.com '
>>> s.rstrip ('. com ')
' Www.baidu '
Third, Text Search
1. Find () finds the first matching string, returns 1 if not found
>>> s = "Hello, world"
>>> s.find ("Hello")
0
>>> S.find ("abc")
-1
2, Starswitch (chars) checks whether the string starts with the specified character, Endswitch () checks whether the string ends with the specified string
Python Note 5 (string)-20160921