python str base64
To encode a string to base64 in Python, you can use the base64 module. Here's an example:
import base64
string = "Hello, World!"
encoded_string = base64.b64encode(string.encode("utf-8")).decode("utf-8")
print(encoded_string)
This will output the base64 encoded string:
SGVsbG8sIFdvcmxkIQ==
To decode a base64 string back to its original form, you can use the b64decode method:
decoded_string = base64.b64decode(encoded_string).decode("utf-8")
print(decoded_string)
This will output the decoded string:
Hello, World!
原文地址: https://www.cveoy.top/t/topic/jgHS 著作权归作者所有。请勿转载和采集!