From 03df7ed032fd48fe151549b8e4fb703757201715 Mon Sep 17 00:00:00 2001 From: Churreesha Date: Thu, 15 Jun 2023 02:21:53 -0400 Subject: [PATCH 1/7] Created id term for Python built-in function --- .../concepts/built-in-functions/id/id.md | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 content/python/concepts/built-in-functions/id/id.md diff --git a/content/python/concepts/built-in-functions/id/id.md b/content/python/concepts/built-in-functions/id/id.md new file mode 100644 index 00000000000..4dc74099177 --- /dev/null +++ b/content/python/concepts/built-in-functions/id/id.md @@ -0,0 +1,106 @@ +--- +Title: 'id()' +Description: 'The id() function gives a unique number for any object in Python. This number is the location of the object in the computer’s memory. +This will be consistent for the duration of the object's lifetime' +Subjects: + - 'Computer Science' + - 'Data Science' + +Tags: + - 'Functions' + - 'Methods' + - 'Id' + - 'Objects' + - 'Numbers' + - 'Memory' + - 'Debugging' + +CatalogContent: + - 'learn-python-3' + - 'paths/computer-science' + - 'paths/data-science' +--- + +The **id() function** gives a unique number for any object in Python. This number is the location of the object in the computer’s memory. +This will be consistent for the duration of the object's lifetime + +## Syntax + +```pseudo +id(object) +``` + +The parameter can be any given object such as a string, list, number, dictionary etc. + +## Example + +In the example below, when the 2 **immutable** variables are executed via the id() function, +they return the same value pointing to the same location in memory. +This is because immutable objects don't change. Let's use the immutable **string** object to demonstrate this: + + ```py +color = 'green' + +favColor = 'green' + +print(id(color)) + +print(id(favColor)) +``` + +This example results in the following output: +```shell +# Output of color: 140307997340656 +# Output of favColor: 140307997340656 +``` + +## Example 2 + +In this next example, we will execute the id() function with 2 **mutable** variables. +Take note of how they will return different values and 2 separate unique ids. +This is because mutable objects are able to change. Let's use the mutable **list** object to demonstrate this: + +```py +animals = ['lions', 'tigers', 'bears'] + +favAnimals = ['lions', 'tigers', 'bears'] + +print(id(animals)); + +print(id(favAnimals)); +``` + +This example results in the following output: +```shell +# Output of animals: 140279020355392 +# Output of favAnimals: 140279020204352 +``` + +## Codebyte Example + +The following example displays the output of the immutable **number** object: + + +```codebyte/python +hello = 30; +goodbye = 30; + +print(id(hello)) +print(id(goodbye)) +``` + +## Codebyte Example 2 + +The following example displays the output of the mutable **dictionary** object: + + +```codebyte/python +fruit = {"name": "Banana", "color": "yellow"} +favFruit = {"name": "Banana", "color": "yellow"} + +print(id(fruit)) +print(id(favFruit)) +``` + + + From cc33ca0f029e39fe94ecbe7c239c5d456cb7fac2 Mon Sep 17 00:00:00 2001 From: Churreesha Harden Date: Wed, 21 Jun 2023 22:54:25 -0400 Subject: [PATCH 2/7] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I have added the wonderful suggestions! Thank you so much! The only thing I have to do now is to delete the second codebyte example as it was suggested that it's not needed. I will do that in VS Code and push the changes here! 😊 Co-authored-by: SSwiniarski <86081858+SSwiniarski@users.noreply.github.com> Co-authored-by: Daksha Deep --- .../concepts/built-in-functions/id/id.md | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/content/python/concepts/built-in-functions/id/id.md b/content/python/concepts/built-in-functions/id/id.md index 4dc74099177..d7683d12b16 100644 --- a/content/python/concepts/built-in-functions/id/id.md +++ b/content/python/concepts/built-in-functions/id/id.md @@ -1,7 +1,6 @@ --- Title: 'id()' -Description: 'The id() function gives a unique number for any object in Python. This number is the location of the object in the computer’s memory. -This will be consistent for the duration of the object's lifetime' +Description: 'Gives a unique number for any object in Python.' Subjects: - 'Computer Science' - 'Data Science' @@ -21,7 +20,7 @@ CatalogContent: - 'paths/data-science' --- -The **id() function** gives a unique number for any object in Python. This number is the location of the object in the computer’s memory. +The **`id()`** function gives a unique number for any object in Python. This number is the location of the object in the computer’s memory. This will be consistent for the duration of the object's lifetime ## Syntax @@ -30,13 +29,13 @@ This will be consistent for the duration of the object's lifetime id(object) ``` -The parameter can be any given object such as a string, list, number, dictionary etc. +The parameter, `object`, can be any given object such as a string, list, number, dictionary etc. ## Example -In the example below, when the 2 **immutable** variables are executed via the id() function, -they return the same value pointing to the same location in memory. -This is because immutable objects don't change. Let's use the immutable **string** object to demonstrate this: +In the example below, when two **immutable** variables are executed using the id() function, +both return the same value pointing to the same location in memory. +This is because immutable objects don't change. The following example uses the immutable `string` object to demonstrate this: ```py color = 'green' @@ -48,17 +47,18 @@ print(id(color)) print(id(favColor)) ``` -This example results in the following output: +This example results something resembling the following output: + ```shell -# Output of color: 140307997340656 -# Output of favColor: 140307997340656 +140307997340656 +140307997340656 ``` ## Example 2 -In this next example, we will execute the id() function with 2 **mutable** variables. -Take note of how they will return different values and 2 separate unique ids. -This is because mutable objects are able to change. Let's use the mutable **list** object to demonstrate this: +In this next example, the id() function will be executed with two **mutable** variables. +Take note of how the function will return different values and two separate unique ids. +This is because mutable objects are able to change. The mutable `list` object can be used to demonstrate this: ```py animals = ['lions', 'tigers', 'bears'] @@ -70,15 +70,16 @@ print(id(animals)); print(id(favAnimals)); ``` -This example results in the following output: +This example results in something resembling the following output: + ```shell -# Output of animals: 140279020355392 -# Output of favAnimals: 140279020204352 +140279020355392 +140279020204352 ``` ## Codebyte Example -The following example displays the output of the immutable **number** object: +The following example displays the output of the immutable `number` object: ```codebyte/python From db9a4f51883a55db3ec4510b8c4867eadc9dda45 Mon Sep 17 00:00:00 2001 From: Churreesha Harden Date: Wed, 21 Jun 2023 22:58:44 -0400 Subject: [PATCH 3/7] Update id.md I deleted the second codebyte example --- content/python/concepts/built-in-functions/id/id.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/content/python/concepts/built-in-functions/id/id.md b/content/python/concepts/built-in-functions/id/id.md index d7683d12b16..d43b5b9756b 100644 --- a/content/python/concepts/built-in-functions/id/id.md +++ b/content/python/concepts/built-in-functions/id/id.md @@ -90,18 +90,7 @@ print(id(hello)) print(id(goodbye)) ``` -## Codebyte Example 2 -The following example displays the output of the mutable **dictionary** object: - - -```codebyte/python -fruit = {"name": "Banana", "color": "yellow"} -favFruit = {"name": "Banana", "color": "yellow"} - -print(id(fruit)) -print(id(favFruit)) -``` From 5b292d7fe25d7b244c14eb31a5d8eeb65966081c Mon Sep 17 00:00:00 2001 From: Churreesha Harden Date: Wed, 21 Jun 2023 23:12:53 -0400 Subject: [PATCH 4/7] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I made additional suggested changes eliminating extra white space! 😊 Co-authored-by: Daksha Deep --- content/python/concepts/built-in-functions/id/id.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/content/python/concepts/built-in-functions/id/id.md b/content/python/concepts/built-in-functions/id/id.md index d43b5b9756b..d92870d109a 100644 --- a/content/python/concepts/built-in-functions/id/id.md +++ b/content/python/concepts/built-in-functions/id/id.md @@ -81,7 +81,6 @@ This example results in something resembling the following output: The following example displays the output of the immutable `number` object: - ```codebyte/python hello = 30; goodbye = 30; @@ -92,5 +91,3 @@ print(id(goodbye)) - - From eadf32ff05afb093936a350e9b2628c328573f5a Mon Sep 17 00:00:00 2001 From: Churreesha Harden Date: Wed, 21 Jun 2023 23:40:20 -0400 Subject: [PATCH 5/7] Update content/python/concepts/built-in-functions/id/id.md Co-authored-by: Daksha Deep --- content/python/concepts/built-in-functions/id/id.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/python/concepts/built-in-functions/id/id.md b/content/python/concepts/built-in-functions/id/id.md index d92870d109a..4a30ee95bff 100644 --- a/content/python/concepts/built-in-functions/id/id.md +++ b/content/python/concepts/built-in-functions/id/id.md @@ -90,4 +90,3 @@ print(id(goodbye)) ``` - From aff2735fff15a451c2b803a6d6a2c30131e88889 Mon Sep 17 00:00:00 2001 From: SSwiniarski <86081858+SSwiniarski@users.noreply.github.com> Date: Thu, 22 Jun 2023 11:45:38 -0400 Subject: [PATCH 6/7] Update and rename content/python/concepts/built-in-functions/id/id.md to content/python/concepts/built-in-functions/terms/id/id.md --- .../python/concepts/built-in-functions/{ => terms}/id/id.md | 4 ---- 1 file changed, 4 deletions(-) rename content/python/concepts/built-in-functions/{ => terms}/id/id.md (99%) diff --git a/content/python/concepts/built-in-functions/id/id.md b/content/python/concepts/built-in-functions/terms/id/id.md similarity index 99% rename from content/python/concepts/built-in-functions/id/id.md rename to content/python/concepts/built-in-functions/terms/id/id.md index 4a30ee95bff..db6a6550aeb 100644 --- a/content/python/concepts/built-in-functions/id/id.md +++ b/content/python/concepts/built-in-functions/terms/id/id.md @@ -4,7 +4,6 @@ Description: 'Gives a unique number for any object in Python.' Subjects: - 'Computer Science' - 'Data Science' - Tags: - 'Functions' - 'Methods' @@ -13,7 +12,6 @@ Tags: - 'Numbers' - 'Memory' - 'Debugging' - CatalogContent: - 'learn-python-3' - 'paths/computer-science' @@ -88,5 +86,3 @@ goodbye = 30; print(id(hello)) print(id(goodbye)) ``` - - From 56c01623729efd309f198f06d5912123370f9e2b Mon Sep 17 00:00:00 2001 From: Caupolican Diaz Date: Thu, 22 Jun 2023 09:36:55 -0700 Subject: [PATCH 7/7] review edits --- .../built-in-functions/terms/id/id.md | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/content/python/concepts/built-in-functions/terms/id/id.md b/content/python/concepts/built-in-functions/terms/id/id.md index db6a6550aeb..9a68057fd8d 100644 --- a/content/python/concepts/built-in-functions/terms/id/id.md +++ b/content/python/concepts/built-in-functions/terms/id/id.md @@ -4,22 +4,19 @@ Description: 'Gives a unique number for any object in Python.' Subjects: - 'Computer Science' - 'Data Science' -Tags: +Tags: - 'Functions' - 'Methods' - 'Id' - - 'Objects' - - 'Numbers' - 'Memory' - 'Debugging' -CatalogContent: +CatalogContent: - 'learn-python-3' - 'paths/computer-science' - 'paths/data-science' --- -The **`id()`** function gives a unique number for any object in Python. This number is the location of the object in the computer’s memory. -This will be consistent for the duration of the object's lifetime +The **`id()`** function gives a unique number for any object in Python. This number is the location of the object in the computer’s memory. This will be consistent for the duration of the object's lifetime. ## Syntax @@ -27,15 +24,15 @@ This will be consistent for the duration of the object's lifetime id(object) ``` -The parameter, `object`, can be any given object such as a string, list, number, dictionary etc. +The parameter, `object`, can be any given object such as a string, list, number, dictionary, etc. ## Example -In the example below, when two **immutable** variables are executed using the id() function, -both return the same value pointing to the same location in memory. -This is because immutable objects don't change. The following example uses the immutable `string` object to demonstrate this: +In the example below, when two **immutable** variables are compared using the `id()` function, both return the same value pointing to the same location in memory. - ```py +This is because immutable objects don't change. The following example uses an immutable `string` object to demonstrate this: + +```py color = 'green' favColor = 'green' @@ -45,7 +42,7 @@ print(id(color)) print(id(favColor)) ``` -This example results something resembling the following output: +This example results in something resembling the following output: ```shell 140307997340656 @@ -54,18 +51,18 @@ This example results something resembling the following output: ## Example 2 -In this next example, the id() function will be executed with two **mutable** variables. -Take note of how the function will return different values and two separate unique ids. -This is because mutable objects are able to change. The mutable `list` object can be used to demonstrate this: +In this next example, the `id()` function will be executed with two **mutable** variables. Take note of how the function will return different values: two separate unique ids. + +This is because mutable objects are able to change. A mutable `list` object can be used to demonstrate this: -```py +```py animals = ['lions', 'tigers', 'bears'] favAnimals = ['lions', 'tigers', 'bears'] -print(id(animals)); +print(id(animals)) -print(id(favAnimals)); +print(id(favAnimals)) ``` This example results in something resembling the following output: @@ -75,13 +72,13 @@ This example results in something resembling the following output: 140279020204352 ``` -## Codebyte Example +## Codebyte Example -The following example displays the output of the immutable `number` object: +The following example displays the output of two immutable `number` objects: ```codebyte/python -hello = 30; -goodbye = 30; +hello = 30 +goodbye = 30 print(id(hello)) print(id(goodbye))