How to encode and decode a string in python? | Sololearn: Learn to code for FREE!

+3

How to encode and decode a string in python?

i use this code but I got error. x='Hello man' y=x.encode('base64','strict') print(y) error= 'base64' is not a text encoding; use codecs.encode() to handle arbitrary codecs.

9/4/2018 4:28:01 PM

Maninder $ingh

1 Answer

New Answer

+5

In Python3, if you want base64 import base64, use b64encode(). (Note, b64encode expects bytestrings) bytestrings: bytes("string", "ascii") "string".encode() b"string" bytestring -> normal: b"string".decode() ...