Python strings are widely used in computer languages. Few people know that Python strings contain two encoding and decoding functions. The following is an introduction to the article. I hope you will learn from the following articles. The following is an introduction to this article.
Python string, which contains two functions:
- String.maketrans(from, to)
# Returns a 256-character translation table, where the characters in from are converted to, so the from and to must be of the same length.
- S.translate(table[,deletechars])
# Use the post-production translation table of the above function to translate S and delete some characters in deletechars. Note that if S is a unicode string, the deletechars parameter is not supported. You can translate a character into None to achieve the same function. In addition, you can use the functions of the codecs module to create more powerful translation tables.
Python strings also have a pair of encoding and decoding functions:
- S.encode([encoding,[errors]])
# Encoding can have multiple values, such as gb2312 gbk gb18030 bz2 zlib big5 bzse64. The default errors value is "strict", which means UnicodeError. Possible values include
- 'ignore', 'replace',
- 'xmlcharrefreplace',
- 'backslashreplace'
And all values registered through codecs. register_error. This part of content involves the codecs module, not the plain white
- S.decode([encoding,[errors]])
Test functions of Python strings, which are not in the string module. These functions return bool values:
- S.startwith(prefix[,start[,end]])
# Whether it is all letters and numbers with at least one character S. isalpha () # whether it is all letters with at least one character S. isdigit () # whether it is all numbers with at least one character S. isspace () # whether it is all blank characters with at least one character S. islower () # whether all letters in S are small S. isupper () # Whether the letters in S are uppercase S. whether istitle () # S is capitalized.