Created
June 14, 2025 08:52
-
-
Save bockor/f3b450244ca72330f97ca1ed72da18e5 to your computer and use it in GitHub Desktop.
python dictionary nested get
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| The walrus operator “:=” is an operator used to evaluate, assign, and return value from a single statement in Python. | |
| It was introduced in Python 3.8 | |
| """ | |
| sss = {'color': 'red', 'size': 'l', 'clips': {'number': 6, 'material': 'metal'}} | |
| if value := sss.get("clips", {}).get("number"): | |
| print(f"Number of clips: {value}") | |
| """ | |
| Number of clips: 6 | |
| """ | |
| if value := sss.get("clips", {}).get("numberxxx"): | |
| print(f"Number of clips: {value}") | |
| """ | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment