Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

please explain me Boolean in python

+13 votes
asked Aug 18 by Rachel Gajbhiv (220 points)

3 Answers

+1 vote
answered Aug 28 by Peter Minarik (80,300 points)

This site covers the basics. Go ahead and check it out.

0 votes
answered Aug 30 by Murat Gezer (140 points)

In the Python programming language, Booleans are data types that can take one of two values: True or False. They are used to represent the result of a logical test, such as whether a condition is met.

For example, the following code checks if the number 10 is even:

def is_even(number):
  """Returns True if the number is even, False otherwise."""
  return number %2 == 0

print(is_even(10)) # True
print(is_even(9)) # False

is_even() takes a number as input and returns a Boolean value. The return statement returns True if the number is even and False if the number is odd.

In the first print statement, is_even() is called with the number 10 as input. Since 10 is even, the function returns True and this value is printed to the console. In the second print statement, is_even() is called with the number 9 as input. Since 9 is odd, the function returns False and this value is printed to the console.

Booleans are used in many other parts of Python, such as conditional statements and loops.

commented Sep 12 by Rakesh Hussenpalli (100 points)
In Python, For suppose write an conditions between any number of variables or values.
If conditions are satisfy It returns True otherwise False.  So Boolean are (True or False)

x=a<b  #condition
print(x)  #True

In the above code, given condition is satisfy.
So it returns True
+1 vote
answered Nov 7 by Gulshan Negi (1,380 points)
Well, here is the code.

x = 5
y = 10

# Example of a boolean expression
is_greater = x > y  # Evaluates to False

and now an expression of code:

== for equal
!=  for not equal
<  for less than
>  for greater than
<=  for less than or equal to
>=  for greater than or equal to

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.