Home>Article>Backend Development> python3 method to determine if a list is an empty list

python3 method to determine if a list is an empty list

不言
不言 Original
2018-05-05 10:32:30 2959browse

This article mainly introduces the method of judging whether a list is an empty list in python3. It has certain reference value. Now I share it with you. Friends in need can refer to it

python3 determines the empty list

@(python3)

There is a need to determine whether the list is empty. I have tried many methods, such as:

a = [] if a is not None: COMMAND

a = [] if a[0] is None: COMMAND

All kinds of messy logic are always unsatisfactory. it's actually really easy.

a = [] if a: COMMAND

An empty list is equal to False,

Then direct if a is to determine the command that needs to be executed when the list is not empty

a = [] if len(a): COMMAND

Similarly, len(a) = 0

When a is not empty, execute Command

Related recommendations :

Python determines whether two lists are instances of the parent-child set relationship

Python determines whether a set is a subset of another set method

The above is the detailed content of python3 method to determine if a list is an empty list. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn