How to exclude NoneType class while reading string in Python

后端 未结 2 733
渐次进展
渐次进展 2021-01-29 08:54

I have a list that is pulled into python from Google Sheets. Some of the cells are empty and return a value of None.

I checked the class type for these \'None\' values a

相关标签:
2条回答
  • 2021-01-29 09:56
    for i, val in enumerate(some_list):
        if val is not None:
            print (i,val)
    

    If you wish to skip None and blank values:

    for i, val in enumerate(some_list):
        if val is not None and val != "":
            print (i,val)
    
    0 讨论(0)
  • 2021-01-29 09:57

    In case, when gapes in i are not needed:

    for i, val in enumerate([x for x in some_list if x]):
        ...
    
    0 讨论(0)
提交回复
热议问题