truthiness
How Python treats any value as true or false in a condition: zero, empty collections, empty strings and None are false; nearly everything else is true.
In more detail
So if items: means if the list is not empty, and while line: stops at an empty string. The short list of false values is False, None, 0, 0.0, "", [], (), {} and set(). It is also why x == 1 or 2 is always true.
Related terms
- Boolean — A value that can only be true or false.
- condition — An expression that is tested for being true or false, such as weight > 50, to decide what a program does next.
- None value — Python's special value meaning nothing here, which is what a function returns if it has no return statement.
- logical operator — An operator such as AND, OR or NOT that combines or reverses true-or-false conditions.
Taught in
- Any Type As A Condition — Hands-on Python: Complete Video Course & Book
- Chapter Three In One Sitting — Hands-on Python: Complete Video Course & Book
- Literals, Names And Four Number Bases — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Fundamentals Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Branching With If, Elif And Else — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Conditions The Exam Loves — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Control Flow Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Lambdas, map() And filter() — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Comprehensions, Closures And Files Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep