All variables in Python are references. Elementary data types aren't an exception.
In the first example, you reassign b. It no longer references the same object as a.
In the second example, you modify b. Since you've previously set a and b to be references to the same object, the modification applies to a as well.
Understanding references in Python - Stack Overflow
What's a good Python reference?
reference - How does Python referencing work? - Stack Overflow
How does python store things in lists vs integers? - Stack Overflow
All variables in Python are references. Elementary data types aren't an exception.
In the first example, you reassign b. It no longer references the same object as a.
In the second example, you modify b. Since you've previously set a and b to be references to the same object, the modification applies to a as well.
For a better grasp of this kind of issues, I would encourage you to use the Online Python Tutor. This is an extremely handy tool that renders a graphical representation of the objects in memory while the code is executed step by step.
To show the Online Python Tutor in action I have splitted a toy example into small snippets and then captured the corresponding screenshots. Hopefully this will help you figure out how Python referencing works.
a = 1
b = a

b = 2

x = [a, b]
y = x

y[1] = 3

If you want to play around with this code, follow this link.
I'm going to be going to a coding competition in about a month, and we're not allowed to use any online resources, but we can bring printed material. I have some experience with Python but I still find myself googling and looking through the official documentation a fair bit. What would be a good reference I could bring?
After a little bit of googling it sounds like Fluent Python or Learning Python might be good, and I also saw someone mention Python Distilled which also sounds interesting.. I'm going to see if I can find any of these at a local bookstore or library so I can flip through them, but I don't know if maybe I'm missing something that would be a good resource to bring. I saw Think Python on the list of recommended books for this reddit which also sounds promising, although I guess I'd have to get it printed out somewhere
The competition involves some leetcode-esque programming problems, if that helps at all as far as what kind of content would be most useful.
In Python a variable is not a box that holds things, it is a name that points to an object. In your code:
d = { 'm': [1,2,3] }--> binds the namedto a dictionarym = d['m']--> binds the namemto a listm = m[1:]--> binds the namemto another list
Your third line is not changing m itself, but what m is pointing to.
To edit the elements in the list what you can do is:
m = d['m']
for i, item in enumerate(m):
result = do_something_with(item)
m[i] = result
Ethan Furman did an excellent job of explaining how Python internals work, I won't repeat it.
Since m really does represent the list inside the dictionary, you can modify it. You just can't reassign it to something new, which is what happens when you use = to equate it to a new slice.
To slice off the first element of the list for example:
>>> m[0:1] = []
>>> d
{'m': [2, 3]}