Python Programming - Standard Libraries - Discussion

Discussion Forum : Standard Libraries - General Questions (Q.No. 83)
83.
How can you use the hashlib module in Python to calculate the SHA-256 hash of a string?
hashlib.sha256(string.encode()).hexdigest()
hashlib.hash256(string.encode())
hashlib.sha256(string).hexdigest()
hashlib.hash256(string)
Answer: Option
Explanation:
import hashlib

# Example usage of hashlib module for calculating the SHA-256 hash of a string
string = 'Hello, World!'
hashed_string = hashlib.sha256(string.encode()).hexdigest()
print(hashed_string)
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.