Educational collection of surprising Python code snippets that demonstrate counter-intuitive behaviors and language internals
Overall
score
93%
A utility that helps developers understand Python's string identity behavior and the difference between identity (is) and equality (==) checks.
Implement a function that determines whether a string will be interned by CPython based on its characteristics.
Implement a function that compares two strings using both identity (is) and equality (==) operators and returns the results.
@generates
def will_be_interned(string_value: str) -> bool:
"""
Determines if a string will be interned by CPython based on its characteristics.
Args:
string_value: The string to check
Returns:
True if the string will be interned, False otherwise
"""
pass
def compare_strings(str1: str, str2: str) -> dict:
"""
Compares two strings using both identity (is) and equality (==) operators.
Args:
str1: First string to compare
str2: Second string to compare
Returns:
A dictionary with keys 'equal' (bool) and 'identical' (bool)
"""
passEducational resource explaining Python's string interning and identity behavior.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/pypi-wtfpythondocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10