Narrator: So up until now,
we learned that strings can be accessed quite easily.
And using the square brackets,
we can access different parts of the string.
And this idea of a start,
a stop,
and a step over
is what we call slicing or string slicing,
because we can slice the string however we like.
But we also need to learn another important term
that's gonna come up again and again throughout this course.
And as a matter of fact, it's an important concept that
as you get more advanced into programming,
you really need to understand.
what is this concept?
Well, it's this idea of immutability.
It's an important term in programming.
What does immutability mean?
Well, strings in Python are immutable.
That means they cannot be changed.
What do I mean by that?
Now that we've assigned selfish this value
this string,
well...
I can reassign it, right?
I can say selfish is 100 now,
and if I print selfish
and I click run, that works.
But if I instead do something like
the first index of selfish is going to equal eight,
and I click run
I get an error.
I get a type error saying,
String object does not support item assignment.
Why is that?
Because strings are immutable.
That is, I cannot change
the value of this
once it's created.
I can't just immediately change it to 8, 1-2-3-4-5-6-7.
Nope, it has to stay the same.
The only way that I can remove this or change this
is to completely reassign the value.
So that in memory,
Python removes all of this from our bookshelf of memory
and instead just assigns eight into the zero bookshelf
and removes everything else because we don't use it anymore.
Now, this idea of immutability
is something we'll explore more and more,
especially when we start talking about lists.
But for now, just remember
that you can't reassign part of a string.
Once created, it exists like that in that form.
The only way we can change it is to create something new.
We can do selfish plus eight,
and we can create it that way.
But now this selfish is a whole new string.
This no longer exists,
and a whole new shelf space was created
for us to use this whole new string.
Again, if this doesn't make sense to you
or why it's important just yet, don't worry.
We'll get there.
For now though, I'll see you in the next video.
Bye bye.