Mutability in Python : Python Basics

preview_player
Показать описание
All about mutability and immutability in Python!
Рекомендации по теме
Комментарии
Автор

Thanks a lot ! after reading several texts about mutability, things still were'nt clear for me. Now they are.

wancel
Автор

It’s interesting. Initially, two numbers 5 & 6 have their own IDs, say 4382964480 & 4382964512, respectively. When I try to assign x = 5, python assigns x to the memory cell containing 5. When I make the increment x = x + 1, x takes up the ID of 6 (4382964512). I verified that by trying to print the IDs of 5 and 6. In the nutshell, every number or character has its own predefined ID and I think the ID changes every time we make an assignment. In the example above if I assigned y = x before increasing x to 6, y would still take up the ID 4382964480 which is the ID of the cell containing 5 after x has been changed. As the “append()”, “pop” methods don’t have anything to do with assignment, so it shouldn’t modify the ID cell of the contained objects.

MinhBui-hx
Автор

I'm curious, what will happen if we just edit the first value of X (3) to 4 without telling python that X +=1? I'm just getting started with programming and i'm terribly confused at all these.

all_about_construction
Автор

But as data analyst, do we need to care about mutability? We need to care about different data objects for performance considerations; but why should we care about mutability as data science analyst?

sgpleasure
Автор

Actually, when I added an element to a list using + (experiment 4), the id of (dict) l remained the same...

jintao
join shbcf.ru