On 18 Oct 2026 09:33:56 GMT, Stéphane CARPENTIER wrote:
> The issue wasn't about assigning a new dictionary to a variable, but
> adding some values in it. Some methods didn't worked for adding
> values if I didn't assign an empty dictionary or an empty list
> first, before doing anything on it.
Well, naturally, if you want to make a change to an object, that object
must a) be mutable, and b) exist in the first place.
E.g. appending to a list:
>>> a = None
>>> a.append("something")
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
a.append("something")
^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'append'
Naturally that doesn’t work, but
>>> a = []
>>> a.append("something")
>>> a
['something']
Naturally that works. Similarly
>>> a = None
>>> a["colour"] = "green"
Traceback (most recent call last):
File "<python-input-6>", line 1, in <module>
a["colour"] = "green"
~^^^^^^^^^^
TypeError: 'NoneType' object does not support item assignment
doesn’t work either, but
>>> a = {}
>>> a["colour"] = "green"
>>> a
{'colour': 'green'}
does work.
> I managed to do it with other programming languages. I managed to do
> it with python, to. In the end, it worked. But it was more
> cumbersome with python. I'm not saying that a programming language
> should be able to be used without being learned. I'm saying that
> it's not an easier language to use.
I’d be curious to see some more detail about what exactly the
situation was, if you can supply it. Maybe you were thinking in terms
of declaring variables of a prespecified type, when Python doesn’t
really have such a concept?