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

python3 method to determine if a list is an empty list

不言
Release: 2018-05-05 10:32:30
Original
3054 people have browsed it

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
Copy after login

a = []
if a[0] is None:
 COMMAND
Copy after login

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

a = []
if a:
 COMMAND
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template