Differences between Python bin lists[] and [None]

Asked 2 years ago, Updated 2 years ago, 17 views

I don't know the difference between [None] and [] as the title says.

A=[None]
B=[]
A.append(1)
B.append(1)
for i in A:
    print(i)
for i in B:
     print(i)

by turning

None
1
1 

Why is None being printed out? Aren't you adding 1 to the empty list for both? Please answer me.

python

2022-09-21 11:35

1 Answers

[None] is completely different from the empty list []. You can think of it as a list that contains one object called None.

>>> len([])
0
>>> len([None])
1


2022-09-21 11:35

If you have any answers or tips


© 2025 OneMinuteCode. All rights reserved.