Thread View: comp.lang.python
1 messages
1 total messages
Started by Lawrence D’Oliveiro
Sun, 18 Oct 2026 21:59
Re: Back To CS Basics. Fuck AI
Author: Lawrence D’Oliveiro
Date: Sun, 18 Oct 2026 21:59
Date: Sun, 18 Oct 2026 21:59
56 lines
3478 bytes
3478 bytes
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?
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads