Use .get() to access a value by key in a dictionary with a default value.
This makes the code shorter and clearer.
The method returns the value for the key if it exists, otherwise it returns the specified default value.
Example:
user_info = {
"username": "john_doe",
"email": "john@example.com",
# the key "role" is missing
}
email = user_info.get("email", None) # Result: "john@example.com"
user_role = user_info.get("role", "guest") # Result: "guest"👉 @DataScience4
