python sha256 of file

# Python program to find SHA256 hash string of a file
import hashlib
 
filename = input("Enter the input file name: ")
sha256_hash = hashlib.sha256()
with open(filename,"rb") as f:
    # Read and update hash string value in blocks of 4K
    for byte_block in iter(lambda: f.read(4096),b""):
        sha256_hash.update(byte_block)
    print(sha256_hash.hexdigest())

Here is what the above code is Doing:
1. We take the input file name from the user.
2. We create a hashlib sha256 object.
3. We open the file in read binary mode.
4. We iterate over the file in blocks of 4K.
5. We update the hash string value in blocks of 4K.
6. We print the final hexadecimal digest value.