easy +8 pts

Compute SHA256 Hash String

Implement a function that returns the SHA-256 hex digest of a given input string.

Write a function `sha256_hash(s: str) -> str` that takes a string `s` and returns the SHA-256 hash of `s` as a 64-character lowercase hexadecimal string. Use Python's `hashlib` module to compute the hash. The function should accept any string, including empty strings and Unicode characters. The output must always be exactly 64 hexadecimal characters (lowercase). **Input:** A single string `s` (may be empty). **Output:** The SHA-256 hash of the UTF-8 encoded input, as a hex string.

Constraints

Input string length: 0 to 10^5. The function must handle arbitrary Unicode characters. Time complexity: O(n), where n is the length of the string. Space complexity: O(1) additional (excluding output).

Example

>>> sha256_hash('hello')
'2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
>>> sha256_hash('')
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
>>> sha256_hash('Python')
'18885f27b5af9012df19e496460f9294d5ab76128824c6f993787004f6d9a7db'
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Import hashlib and use hashlib.sha256().
Encode the string with UTF-8 before hashing.
Call .hexdigest() to get the hexadecimal string.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.