Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

python - 如何检查列表是否为空?(How do I check if a list is empty?)

For example, if passed the following:

(例如,如果通过以下内容:)

a = []

How do I check to see if a is empty?

(如何检查a是否为空?)

  ask by Ray Vega translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
if not a:
  print("List is empty")

Using the implicit booleanness of the empty list is quite pythonic.

(使用空list隐式布尔值是非常Python的。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...