From aa714c26e4f5279e3000cafd097ab0886fd0b9aa Mon Sep 17 00:00:00 2001 From: Phillip Bridgeman Date: Fri, 9 May 2025 19:50:22 -0500 Subject: [PATCH 1/2] Add example to Python get() method entry --- content/python/concepts/dictionaries/terms/get/get.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/content/python/concepts/dictionaries/terms/get/get.md b/content/python/concepts/dictionaries/terms/get/get.md index 2f6a4e92526..48e4333df08 100644 --- a/content/python/concepts/dictionaries/terms/get/get.md +++ b/content/python/concepts/dictionaries/terms/get/get.md @@ -35,3 +35,11 @@ print(d.get(3)) print(d.get(4)) print(d.get(4, 'empty')) ``` + +## Additional Examples + +### Example: Getting a value safely +```python +user = {"name": "Alex", "age": 30} +print(user.get("email", "Not provided")) +# Output: Not provided From 9919ce535cb20dc5aaa595b4ea69a037264424e3 Mon Sep 17 00:00:00 2001 From: Phillip Bridgeman Date: Fri, 9 May 2025 19:52:54 -0500 Subject: [PATCH 2/2] Revised position of additonal example. --- .../concepts/dictionaries/terms/get/get.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/content/python/concepts/dictionaries/terms/get/get.md b/content/python/concepts/dictionaries/terms/get/get.md index 48e4333df08..575daf28ec9 100644 --- a/content/python/concepts/dictionaries/terms/get/get.md +++ b/content/python/concepts/dictionaries/terms/get/get.md @@ -25,6 +25,14 @@ dictionary.get(key, value) Where `key` is the key of the value to return and `value` is an optional value to return if `key` does not exist in `dictionary`. If `value` isn't specified, the fallback value will be `None`. +## Additional Examples + +### Example: Getting a value safely +```python +user = {"name": "Alex", "age": 30} +print(user.get("email", "Not provided")) +``` + ## Codebyte Example The following example creates a dictionary, then retrieves some values for keys using `.get()`: @@ -35,11 +43,3 @@ print(d.get(3)) print(d.get(4)) print(d.get(4, 'empty')) ``` - -## Additional Examples - -### Example: Getting a value safely -```python -user = {"name": "Alex", "age": 30} -print(user.get("email", "Not provided")) -# Output: Not provided