Home  >  Article  >  Backend Development  >  What does encoding mean in python?

What does encoding mean in python?

(*-*)浩
(*-*)浩Original
2019-07-03 14:34:3722607browse

encoding means encoding. In python, the Unicode type is the basic type of encoding.

What does encoding mean in python?

#The Python encode() method encodes a string in the encoding format specified by encoding. The errors parameter can specify different error handling schemes.

encode() method syntax: (Recommended learning: Python video tutorial)

str.encode(encoding='UTF-8',errors='strict')

Parameters

encoding -- The encoding to use, such as "UTF-8".

errors --Set different error handling options. The default is 'strict', which means encoding errors cause a UnicodeError. Other possible values ​​are 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' and any value registered via codecs.register_error().

Return value

This method returns the encoded string.

The following examples show examples of the encode() method:

#!/usr/bin/python

str = "this is string example....wow!!!";

print "Encoded String: " + str.encode('base64','strict')

The output results of the above examples are as follows:

Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=

More Python related technical articles, Please visit the Python Tutorial column to learn!

The above is the detailed content of What does encoding mean in python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn