Check for True or False in Python Last Updated : 18 Nov, 2024 Comments Improve Suggest changes Like Article Like Report Python has built-in data types True and False. These boolean values are used to represent truth and false in logical operations, conditional statements, and expressions. In this article, we will see how we can check the value of an expression in Python.Common Ways to Check for True or FalsePython provides various ways to check if an expression is evaluated as True or False. Let us see them one by one:Using bool() FunctionThe bool() function is an in-build Python function that returns the Boolean value of an expression. Python # returns False as 'a' is 0 a = 0 print(bool(a)) # returns True as 5 is greater then 3 b = 5 > 3 print(bool(b)) # returns True as 'c' is True c = True print(bool(c)) # returns True as 'f' is not an empty string d = "GfG" print(bool(d)) # returns False e = None print(bool(e)) Using Comparison OperatorsWe can use Comparison operator to check if an expression evaluates to True or False. == and != Operator can be used with if condition or while statement to evaluate an expression. Python a = 10 b = 10 # checking the value using the equality operator print(a == b) # checking the value using inequality operator print(a != b) OutputTrue False Using Logical OperatorsLogical Operators (and, or, not) allow combining multiple conditions. Python a = True b = False # Using different logical operators print(a and b) # False (both conditions must be True) print(a or b) # True (at least one condition is True) print(not a) # False (negation of True) OutputFalse True False Using Identity OperatorsIdentity Operator such as 'is' and 'is not' Operator can be used to check if two variables reference the same object in memory. They are particularly useful when you need to check for object identity rather than equality. Python a = 10 b = 10 # True (both variables point to the same object) print(a is b) # False (both variables point to the same object) print(a is not b) OutputTrue False Comment More infoAdvertise with us Next Article Check for True or False in Python T tanyasehr88x Follow Improve Article Tags : Python python Practice Tags : pythonpython Similar Reads Check If Value Is Int or Float in Python In Python, you might want to see if a number is a whole number (integer) or a decimal (float). Python has built-in functions to make this easy. There are simple ones like type() and more advanced ones like isinstance(). In this article, we'll explore different ways to check if a value is an integer 4 min read Python True Keyword True is a built-in Boolean value that represents truth or logical true value. It is one of the two Boolean constants (True and False) and is often used in conditions, loops and logical operations.Python treats True as 1 when used in arithmetic operations and as a truthy value in conditional statemen 2 min read Check if String Contains Substring in Python This article will cover how to check if a Python string contains another string or a substring in Python. Given two strings, check whether a substring is in the given string. Input: Substring = "geeks" String="geeks for geeks"Output: yesInput: Substring = "geek" String="geeks for geeks"Output: yesEx 8 min read Python If Else in One Line In Python, if-else conditions allow us to control the flow of execution based on certain conditions. While traditional if-else statements are usually written across multiple lines, Python offers a more compact and elegant way to express these conditions on a single line. Python if-else in One LineIn 2 min read Python - How to Check if a file or directory exists Sometimes it's necessary to verify whether a dictionary or file exists. This is because you might want to make sure the file is available before loading it, or you might want to prevent overwriting an already-existing file. In this tutorial, we will cover an important concept of file handling in Pyt 5 min read Like