Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand two Decoding and Decoding functions in Python string

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article to share with you is about how to understand the Python string in the two decoding and decoding functions, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.

Python string containing two functions:

String.maketrans(from, to)

#Returns a translation table of 256 characters, where the characters in from are converted to to one by one, so from and to must be equal in length.

S.translate(table[,deletechars])

#Use the above function to translate S and delete some characters from deletechars. Note that if S is a unicode string, then deletechars is not supported, and the same functionality can be achieved by translating a character to None. You can also use 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 and so on. The default value for errors is "strict," which means UnicodeError. Possible values and

'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace'

and all values registered through codecs.register_error. This section deals with the codecs module, not specifically

S.decode([encoding,[errors]])

Python string test functions, such functions are not in the string module, these functions return bool values:

S.startwith(prefix[,start[,end]])

#Are all letters and numbers, with at least one character S.isalpha() #Are all letters, with at least one character S.isdigit() #Are all numbers, with at least one character S.isspace() #Are all white space characters, with at least one character S.islower() #Are all letters in S small S.isupper() #Are all letters in S capital S.istitle()#S capital.

The above is how to understand the two decoding and decoding functions in Python strings. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report