Back to Lesson
Safe Function Parsing
Reduce duplicate calls executing walrus assignments.
Instructions
- Python 3.8+ introduced! Allowing you to assert evaluations directly within conditional scopes.
:= - Assume a mocked processing pipeline returning integer quantities. Function simulation:
def get_count(): return 5 - Instead of calling, and then
count = get_count()... combine them! Determineif count > 0:.if (count := get_count()) > 0: - If it enters the block, print.
f"{count} valid items"
main.py
main.py
Ctrl + Enter