To convert a string to an MD5 hash in Python, you can use the hashlib
module.
Here's an example code block:
main.py120 chars6 lines
In this code, we first import the hashlib
module. We then define a string - "Hello World!" - and create an MD5 hash object from it using hashlib.md5()
. We encode the string using .encode()
since the hashlib.md5()
function requires a bytes-like object. Finally, we print the hex digest of the hash using .hexdigest()
.
gistlibby LogSnag