Is it possible to assign a list with empty values in Python?
This is possible:
x = []
But I want to do something like:
x = [4,7,2, ,8,9,1]
with an empty value inside. The reason is that I have a large number of lists with 7 values and sometimes one of the values are unavailable. I need to keep say 8 as x[4],9 as x[5] etc.
My thoughts:
Maybe I should just put a number like 999 inside, or a string "empty" and tell my code to ignore 999 or "empty" or whatever.
What is the best option here?
Use None
for the "empty" value.
a = [1,2,3,4,5]
b = [11,22,None,44,55]
Another option other than using None
is to use some other unique object such as empty = object()
as this allows None
to be used as a list item and then test if the list item is empty via l[x] is empty
.
Use "None". It indicates that there is no value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With