Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8320887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:49:19+00:00 2026-06-08T22:49:19+00:00

I was testing a list to see if it’s empty or not. Normally I

  • 0

I was testing a list to see if it’s empty or not. Normally I use len(list) == 0 and I vaguely remembered reading a little while ago that the correct way to test if a list is empty was whether it was True or false.

So I tried list is False, and that returned False. Maybe I’m suppose to be using == ?
Nope, that also returned false. list is True, returned false as did list == True.

Now I’m confused so I do a quick google and end up at: Best way to check if a list is empty

The top answer is:

if not a:
    print "List is empty"

So I search around some more and end up in the python manual where 4.1 states:

Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below. The following values are considered false:

any empty sequence, for example, ”, (), [].

Now I’m plain confused. If I test a list as if not list, it works fine. But if an empty list is false, then why can’t I just do if list is False or if list == False?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:49:21+00:00Added an answer on June 8, 2026 at 10:49 pm

    An empty list is not False, but when you convert it to a boolean, it converts to False. Likewise for dicts, tuples, strings, etc.:

    >>> [] == False
    False
    >>> bool([]) == False
    True
    >>> {} == False
    False
    >>> bool({}) == False
    True
    

    When you put something in the condition of an if clause, it is its boolean value that is used for testing the if. That’s why if someList is the same as if bool(someList). Likewise, not foo does a boolean not, so not [] equals True.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i'm testing the following code it's suppose to list all apps installed on
During testing, I'm stuck with testing a piece of code that receives a list
Does Flash Builder support tasks list? I'm testing Flash Builder for PHP, and I
I am testing a web app where i delete an item from a list.
I'm currently creating a small silverlight application for testing, to see if it can
Here is one (typical?) example taken from the List.addAll doc that does not seem
I've been wondering about this for a while and I can't see why Google
While setting up Hudson for continous integration testing (on a JeOS server), I've come
I can't see why this isn't working. I have a list, each item has
I am testing BerkeleyDB Java Edition to understand whether I can use it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.