Python Lesson 05 - Dictionaries, Multi-Dimensional Lists, and Mutability

preview_player
Показать описание
In this Python lesson, we look at the very useful dictionary data type, as well as how to deal with lists that have multiple dimensions and a problem to avoid with lists.
------------------------------------------------------------------
Plug into BitMerge

Рекомендации по теме
Комментарии
Автор

quick correction - although maybe a bit too deep for a beginner : You can't use any data type as a key into a dictionary - it has to be a hashable data type. In general most basic types are hashables, but for instance lists are not hashable, and custom objects aren't hashable by default.

anthonyflury
Автор

You got it wrong when you said that when you do x = y = 10, that x & y get 'copies' - they don't - they both refer to the same '10' integer object, the same as later x & y end up referring to the same list. The difference between the two examples is that because the '10' integer is immutable, that when you do x=55 - you are end up rebinding x to a new object - becuase it's original object cannot be changed. In Python everything name is a reference to an object - nothing more and nothing less.. I cover this and other stuff in my blog post :

You might not want to get deep into the detail with beginners - but you should make sure you are correct with the info that you do give them.

anthonyflury