One problem record Python conditional if statement

Copyright: As this article have questions, please contact the author micro letter kxymxzs, welcome harassment! https://blog.csdn.net/MG_ApinG/article/details/89513635
nbrList1=[]
if nbrList1:
    print('gg')
if nbrList1 and 5 < len(nbrList1[0][0]) < 30:
    print('gg')
if 5 < len(nbrList1[0][0]) < 30:
    print('gg')
Traceback (most recent call last):
  File "D:\APP\python36\lib\site-packages\IPython\core\interactiveshell.py", line 3267, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-6-f53920ca42b6>", line 1, in <module>
    if 5 < len(nbrList1[0][0]) < 30:
IndexError: list index out of range

The first two statements to determine the error will not be executed properly, the last reported IndexError error, and the second can be used to determine not know whether further judged that the list is empty, in some cases can be used to, for example, I want to take a few list elements is greater than the length of the list 20, if separately to determine whether an empty list and the length of the judgment, the whole cycle will have a lot of questions to determine if together several elif get away, write reptiles may encounter this more often Happening.

Guess you like

Origin blog.csdn.net/MG_ApinG/article/details/89513635