-9

The question is “Is there a way to clear the value of a variable in python?”, and the accepted answer is to assign to that variable a value of None.

However, assigning to a variable a value of None and deleting that variable don’t seem to be functionally identical. And even if giving the variable an empty value was the goal, wouldn't self.left = '' (or something else) still be a more accurate solution than self.left = None?

Two possible arguments for why self.left = None shouldn't be considered the accepted answer for this question:

>>> a = "a"
>>> b = "b"
>>> c = "c"
>>> d = ['foo', 'bar', 'choco', 'Kiki', 'Buba']
>>> #Argument N1
>>> a = ""
>>> del b
>>> c = None
>>> type(a)
<class 'str'>
>>> a
''
>>> type(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>> type(c)
<class 'NoneType'>
>>> c
>>>
>>> #Argument N2
>>> d[1] = a
>>> d
['foo', '', 'choco', 'Kiki', 'Buba']
>>> d = ['foo', 'bar', 'choco', 'Kiki', 'Buba']
>>> d[1] = b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>> d
['foo', 'bar', 'choco', 'Kiki', 'Buba']
>>> d[1] = c
>>> d
['foo', None, 'choco', 'Kiki', 'Buba']

1 Answer 1

10

The acceptance mark is set by the user asking the question, and it is completely up to them to choose which answer they accept. It just means that it is the answer that helped them the most - it does not mean it is a helpful answer for everybody or even a correct answer.

So, no, we can't and shouldn't change the accepted answer. You can comment on it instead, and you can (and should) downvote incorrect answers and upvote correct answers.

See "What does it mean when an answer is accepted?" in the help section.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .