Programming Terms: Mutable vs Immutable

Programming Terms: Mutable vs Immutable

Corey Schafer

8 лет назад

101,092 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

potatoBot
potatoBot - 29.09.2023 08:57

Thank you so much for your generous time and effort!

Ответить
ooo ooo
ooo ooo - 17.12.2022 15:02

There is string buffer in Java too I think but also StringBuilder I always use.
Is it that much of an issue? Is there no garbage collection in Python ?
Good to see you have a series of technical terms to clarify.

Ответить
BHASKAR KUSH.
BHASKAR KUSH. - 11.12.2022 17:46

Great explanation buddy .... Keep up the great work

Ответить
William D'Arrigo
William D'Arrigo - 23.11.2022 02:20

You explained this so clearly. Thanks 😊

Ответить
Dean Bitter
Dean Bitter - 26.10.2022 18:08

your explanation was Awesome.

Ответить
Алексей Соков
Алексей Соков - 21.08.2022 14:28

2022

Ответить
Aditya Mishra
Aditya Mishra - 22.06.2022 10:59

This video feels like finding gold among the archives. Though the tools are outdated (python 2) but the concept remains a timeless asset.

Ответить
Maria Luisa Cáceres Loayza
Maria Luisa Cáceres Loayza - 19.04.2022 16:00

Great video!!

Ответить
bobsonclimber
bobsonclimber - 02.04.2022 11:40

Excellent explanation..thank you

Ответить
JadeJuno
JadeJuno - 14.03.2022 01:16

My main question about this mutable and immutable stuff, is why would you want to have an immutable value over a mutable one?-

Ответить
Colin Maharaj
Colin Maharaj - 06.02.2022 14:53

Immutable mean, don't use that language.

Ответить
anwar sosko
anwar sosko - 30.12.2021 23:27

You're amazing

Ответить
QuarantineGamingUK
QuarantineGamingUK - 27.10.2021 22:37

Thank you so much this was briliantly clear <3

Ответить
Kofer Perk
Kofer Perk - 22.10.2021 10:25

thanks!

Ответить
Viktor Nikolov
Viktor Nikolov - 12.10.2021 23:31

A very helpful video, thank you!

Ответить
Michael
Michael - 03.10.2021 15:06

Many thanks

Ответить
Bassel Kordy
Bassel Kordy - 02.10.2021 16:06

Very informative, Thanks!

Ответить
Farrukh Afzaal
Farrukh Afzaal - 18.09.2021 09:05

Thank you @Corey, this is a wonderful explanation

Ответить
love_radiation
love_radiation - 09.05.2021 11:48

Can you explain dynamically typed programming

Ответить
Rijumone Choudhuri
Rijumone Choudhuri - 04.05.2021 00:25

Thanks so much for explaining why its important to know which objects are mutable and which are not.

Ответить
musicfan2000
musicfan2000 - 13.04.2021 22:10

thank you, king

Ответить
ZeryusXD
ZeryusXD - 01.04.2021 21:34

Excellent explanation thanks!

Ответить
Andrii Pashnov
Andrii Pashnov - 30.03.2021 12:18

and I didn't get the answer what I can use in python instead of str (like StringBuilder in java) ?

Ответить
Clifford Mathew
Clifford Mathew - 26.03.2021 22:43

Thanks

Ответить
Alin Apostol
Alin Apostol - 06.02.2021 05:04

Great explanation, thanks!

Ответить
Peacemekka
Peacemekka - 18.12.2020 12:09

nice.

Ответить
KOLLI VENKATA MADHUKAR
KOLLI VENKATA MADHUKAR - 07.12.2020 21:25

Great Explination 5 articles = 1 Video

Ответить
S Afzal
S Afzal - 06.12.2020 10:21

Thank you for compiling such a beautiful example for explaining the topic.

Ответить
Ayush Bro
Ayush Bro - 10.11.2020 19:10

Is

Ответить
Ankit jhunjhunwala
Ankit jhunjhunwala - 27.09.2020 23:24

Adding one more point, immutability makes the data thread safe.

Ответить
blood bath
blood bath - 16.08.2020 14:32

thank you very much very very much

Ответить
Abhishek Kumar
Abhishek Kumar - 02.08.2020 09:09

Best explanation !!

Ответить
Andy Theodorko
Andy Theodorko - 21.06.2020 17:03

Why not make strings mutable?
What can I use in C# to make the string mutable? What about char[], is this mutable? Any consequences of not using string but using char[]?

Ответить
Alisha Shrestha
Alisha Shrestha - 08.06.2020 09:13

By far the best explanation of immutability for beginners. Thanks!

Ответить
Neil
Neil - 27.05.2020 22:28

I already had a good grasp of mutable and immutable, but I'll admit; your explanation definitely made the distinction clear. Especially with regards to how immutable objects occupy a distinct space of memory and how trying to modify them can create multiple objects in memory. Overall, I learned a lot so thank you very much for posting these. :)

Ответить
Mitchell van Doorn
Mitchell van Doorn - 18.05.2020 21:46

This was clear, thanks!

Ответить
shixian li
shixian li - 08.04.2020 14:45

great video

Ответить
Rachel Winchell
Rachel Winchell - 26.03.2020 04:55

I'm getting a syntax error when I go to print a. wants me to add (). please advise

Ответить
팍준하
팍준하 - 06.03.2020 14:00

Summary:
1. 'Mutable' means that an object can be modified, while 'immutable means it can't.


2. We can check whether a data is mutable or not by printing out the id(memory address) of an object after performing an modification to the data type.


3. Example#1. Strings are immutable in Python. But we can still reassign a whole new string value oto a variable that holds a string. However, it is not possible to modify a substring while keeping the memory address the same.


4. Example#2. Lists are mutable in Python. We can change one item of the list while keeping the memory address of the entire list the same.


5. Why should we know this concept? There are 2 reasons
5-1 We can avoid and fix errors caused by modifying an immutable data type.
5-2 We can speed up our programs. Memories are being shifted when performing operations on immutable objects means that it is going to take a lot more amount of time, and making our program slower. By avoiding operations on immutable data and thus the memory shift, we can improve our program speed.

Ответить
Marcus Lucas
Marcus Lucas - 03.03.2020 07:02

This is the greatest explanation on this top! Can you give more examples when using mutable and immutable variables are good or bad when processing large amounts of data?

Ответить
AB
AB - 13.02.2020 18:53

What’s happening in the employee example? I mean how could I make the list mutable?

Ответить
pavel OoO
pavel OoO - 24.01.2020 00:22

Thanks for clearing the concepts. -the 1000th liker.

Ответить
Pinkfloyd
Pinkfloyd - 22.11.2019 08:36

best video to explain the concept . Thank you

Ответить
Soumya Ranjan Das
Soumya Ranjan Das - 13.11.2019 00:16

Thank you Corey for your time and effort. Keep spreading the knowledge.

Ответить
Ye Gao
Ye Gao - 04.11.2019 07:51

The difference between mutable and immutable objects is very nicely explained in the first half of the video. You are absolutely correct that an application which keeps appending value to an immutable object runs slow as it constantly copies the existing value to a new memory space. However, there is no guarantee that by changing it to a mutable object the application will run fast. Using list, it is indeed the case as list in Python is essentially a variable-sized array which has extra spaces to add new elements. So its operation to append is "amortized" O(1). But if one uses numpy array, then it is essentially the same as using string which copies the existing elements over to a new memory location whenever new elements are appended (i.e. O(N) operation).

Ответить
Rohit Handa
Rohit Handa - 16.10.2019 12:07

Very well explained...!

Ответить
NAL Lilley
NAL Lilley - 29.08.2019 18:59

Super helpful. Thanks. UK CS teacher.

Ответить
Симеон Чакъров
Симеон Чакъров - 28.08.2019 11:29

When'd the garbage collector release the previous addresses when concatenating the string(the example with the html list)?

Ответить
Soham Dutta
Soham Dutta - 20.08.2019 12:26

Dear Corey,
May I please have your mail id, so that I may ask a few things.
Thank You

Ответить