Please tell me how to check the blank list

Asked 2 years ago, Updated 2 years ago, 19 views

When you have an empty list a = [] as follows: Please tell me how to find out if a is empty or not.

python

2022-09-22 22:38

1 Answers

An empty sequence (string, list, or tuple) has a false value Therefore, you can use it as follows:

if not a:
  print "List is empty"

python style guide recommends the following methods.

Recommended method)
    if not seq:
    if seq:

Not recommended)
    if len(seq):
    if not len(seq):


2022-09-22 22:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.