- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Boolean Values in Python
The truth values of an expression is stored as a python data type called bool. There are only two such values in this data type. True and False.
Boolean Data Types
In the below program we find out the data types of True and False Boolean values.
Example
print(True) print(type(True)) print(False) print(type(False))
Output
Running the above code gives us the following result −
True <class 'bool'> False <class 'bool'>
Boolean expression
Boolean expression is an expression that evaluates to a Boolean value. It almost always involves a comparison operator. In the below example we will see how the comparison operators can give us the Boolean values. The bool() method is used to return the truth value of an ex[resison.
Example
Syntax: bool([x]) Returns True if X evaluates to true else false. Without parameters it returns false.
Below we have examples which use numbers streams and Boolean values as parameters to the bool function. The results come out us true or false depending on the parameter.
Example
# Check true a = True print(bool(a)) # Check false a = False print(bool(a)) # Check 0 a = 0.0 print(bool(a)) # Check 1 a = 1.0 print(bool(a)) # Check Equality a = 5 b = 10 print(bool( a==b)) # Check None a = None print(bool(a)) # Check an empty sequence a = () print(bool(a)) # Check an emtpty mapping a = {} print(bool(a)) # Check a non empty string a = 'Tutorialspoint' print(bool(a))
Output
Running the above code gives us the following result −
True False False True False False False False True
- Related Articles
- Boolean Indexing in Python
- Handling higher level Boolean values in SAP system
- BOOLEAN or TINYINT to store values in MySQL?
- Python Boolean Operations
- Boolean list initialization in Python
- How can we enter BOOLEAN values in MySQL statement?
- What is the syntax for boolean values in MongoDB?
- How can I update the boolean values in MySQL?
- Python - Contiguous Boolean Range
- What are boolean operators in Python?
- Parsing A Boolean Expression in Python
- Converting boolean values to positive or negative sign in MySQL?
- Count boolean field values within a single MySQL query?
- How to deal with 'Boolean' values in PHP & MySQL?
- Does MySQL Boolean “tinyint(1)” holds values up to 127?
