Python Programming (83 Blogs) Become a Certified Professional
AWS Global Infrastructure

Data Science

Topics Covered
  • Business Analytics with R (28 Blogs)
  • Data Science (39 Blogs)
  • Mastering Python (62 Blogs)
  • Decision Tree Modeling Using R (1 Blogs)
SEE MORE

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-widget-banner-bg

All you Need to Know about Boolean in Python

Published on Aug 22,2019 19 Views

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-mobile-banner-bg

myMock Interview Service for Real Tech Jobs

  • Mock interview in latest tech domains i.e JAVA, AI, DEVOPS,etc
  • Get interviewed by leading tech experts
  • Real time assessment report and video recording

A boolean value is basically named as TRUE or FALSE. Boolean is one of the basic data types used in every computer programming language. In this computer-world returns, the Boolean value is one of the two possible values which is denoted by TRUE or FALSE. The Following Pointers will be covered in this Boolean in Python article:

 

What is a Boolean value?

Boolean is named after George Boole who first defined the Boolean algebraic for logical expressions in the mid of the 19th century.  Boolean or Boolean logic is called a subset of the algebra used to tell either True or False. Boolean expressions use with conditional operators such as AND, OR, XOR and NOT to compare values.

Boolean in Python

Comparison operators and Logical operators which basically returns the Boolean value and used for making logical decisions and comparing the different values. Boolean, when converted into integers values, would be 0 and 1, 0 as False and 1 as True. Many operations and functions returns to Boolean values.

Many programming languages have various data types Boolean is one among them, Python supports Boolean data type but there are certain other languages which do not support Boolean data type. Boolean or Comparative operators needs two operands to evaluate.

Moving on with this article on Boolean in Python

 

We compare two operands to give value in Boolean values.

Relational Operators.

OperatorsDescriptionExample

Greater Than (>)

The condition turns TRUE if value of left operand is greater than right operand value.

a>b

Less Than (<)

The condition turns TRUE if value of left operand is lesser than right operand value.

a < b

 Equal to (==)

If the value of left and right operand is same the condition turns TRUE.

a == b

Not equal (!=)

If values of two operands are not equal then the condition turns TRUE.

 a != b

Greater than or equal to (>=)

The condition turns TRUE if the left operand value greater than the right operand value.

a >= b

Less than or equal to (<=)

The condition turns TRUE if the left operand value less than the right operand value.

a <= b

Moving on with this article on Boolean in Python

 

Here is the list of Boolean Operators

OperatorsDescriptionExample

Not (!)

Boolean Not

Not (a and b) is false

AND (&&)

If both the value of the operands are true the condition turns TRUE.

a && b

OR (||)

The condition turns true if either one of the operands is TRUE.

a || b

We write Boolean value True not as a string.

True

True

False
False

 

Python supports the bool data type. To get to know the data type

type(True)

bool

 

A couple of the comparison operators listed below with the Boolean values.

1 > 2

False

2 == 2

True

2 > 1

True

3 < 6

True

4 <= 7

True

True-False

Moving on with this article on Boolean in Python

When comparing string Capitalization Counts

‘Bye’ == ‘bye’

False

‘2’ == 2

False

3 != 3 

False

 

Moving on with this article on Boolean in Python

Logical Operators

1 < 2 < 3 

True

1 < 2 >3

False

1 < 2 and 2 > 3

False

1 < 2 and 2 < 3 

True

‘h’ == ‘h’ and 2 == 2 

True

1 < 2 or 2 > 3

True

 

Moving on with this article on Boolean in Python

Not Keyword

Not 1 == 1

False

400 > 5000

False

Not 400 > 5000

True

 

With this, we come to an end of this Boolean in Python article. I hope you got to know the different types of Boolean Operations.

Got a question for us? Please mention it in the comments section of this “Boolean in Python article” and we will get back to you as soon as possible.

To get in-depth knowledge on Python along with its various applications, you can enroll for live Python online training with 24/7 support and lifetime access. 

Comments
0 Comments

Browse Categories

Subscribe to our Newsletter, and get personalized recommendations.