aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar decorator-factory <[email protected]>2020-05-17 14:16:45 +0300
committerGravatar GitHub <[email protected]>2020-05-17 14:16:45 +0300
commit4f76259976491ff68247b0f66a6549b37bc090bd (patch)
tree303e1f78bc093278b7764edc477eb93ce0618747
parentAdd a note on user-defined classes (diff)
Rename `string` to `greeting`
-rw-r--r--bot/resources/tags/mutability.md20
1 files changed, 10 insertions, 10 deletions
diff --git a/bot/resources/tags/mutability.md b/bot/resources/tags/mutability.md
index 3447109ad..ef2f47403 100644
--- a/bot/resources/tags/mutability.md
+++ b/bot/resources/tags/mutability.md
@@ -4,11 +4,11 @@ Imagine that you want to make all letters in a string upper case. Conveniently,
You might think that this would work:
```python
->>> string = "abcd"
->>> string.upper()
-'ABCD'
->>> string
-'abcd'
+>>> greeting = "hello"
+>>> greeting.upper()
+'HELLO'
+>>> greeting
+'hello'
```
`string` didn't change. Why is that so?
@@ -16,13 +16,13 @@ You might think that this would work:
That's because strings in Python are _immutable_. You can't change them, you can only pass around existing strings or create new ones.
```python
->>> string = "abcd"
->>> string = string.upper()
->>> string
-'ABCD'
+>>> greeting = "hello"
+>>> greeting = greeting.upper()
+>>> greeting
+'HELLO'
```
-`string.upper()` creates and returns a new string which is like the old one, but with all the letters turned to upper case.
+`greeting.upper()` creates and returns a new string which is like the old one, but with all the letters turned to upper case.
`int`, `float`, `complex`, `tuple`, `frozenset` are other examples of immutable data types in Python.