Python OR Keyword Last Updated : 08 Mar, 2025 Comments Improve Suggest changes Like Article Like Report Python OR is a logical operator keyword. The OR operator returns True if at least one of the operands becomes to be True. Note:In Python "or" operator does not return True or False. The "or" operator in Python returns the first operand if it is True else the second operand.Let’s start with a simple example to understand how "or" works in a condition. Python age = 16 p = False if age >= 18 or p: print("Access granted") else: print("Access denied") OutputAccess denied Explanation: The if condition is not being evaluated as True because neither of the conditions (age >= 18 or p) are True.Python OR Keyword Truth TableInput 1Input2OutputTrueTrueTrueTrueFalseTrueFalseTrueTrueFalseFalseFalseLet's explore some of the use cases of "or" keyword with examples.Use of "or" in Conditional Statements In the if statement python uses the "or" operator to connect multiple conditions in one expression. Python a = 55 b = 33 if b > a: print("b is greater than a") elif a == b: print("a and b are equal") else: print("a is greater than b") Outputa is greater than b Use of "or" in Loops "or" operator can be used inside loops to control execution based on multiple conditions.Example : Python # break the loop as soon it sees 'k' # or 'f' i = 0 s = 'geeksforgeeks' while i < len(s): if s[i] == 'k' or s[i] == 'f': i += 1 break print(s[i]) i += 1 Outputg e e Using "or" for Default Values"or" keyword is often used to set default values when dealing with empty or None variables. Python user = "" cur_user = user or "Guest" print(cur_user) # when user is empty user = "geeks" cur_user = user or "Guest" # when user in not empty print(cur_user) OutputGuest geeks Explanation: when user is an empty string ("") (which is falsy), "or" selects "Guest".when user contains a value (which is truthy), it gets assigned to cur_user because "or". Comment More infoAdvertise with us Next Article Python OR Keyword S shubhsharma010101 Follow Improve Article Tags : Python python-basics Practice Tags : python Similar Reads Python Keywords Keywords in Python are reserved words that have special meanings and serve specific purposes in the language syntax. Python keywords cannot be used as the names of variables, functions, and classes or any other identifier. Getting List of all Python keywordsWe can also get all the keyword names usin 11 min read Python in Keyword The in keyword in Python is a powerful operator used for membership testing and iteration. It helps determine whether an element exists within a given sequence, such as a list, tuple, string, set or dictionary.Example:Pythons = "Geeks for geeks" if "for" in s: print("found") else: print("not found") 3 min read as Keyword - Python as keyword in Python plays a important role in simplifying code, making it more readable and avoiding potential naming conflicts. It is mainly used to create aliases for modules, exceptions and file operations. This powerful feature reduces verbosity, helps in naming clarity and can be essential whe 3 min read Python def Keyword Python def keyword is used to define a function, it is placed before a function name that is provided by the user to create a user-defined function. In Python, a function is a logical unit of code containing a sequence of statements indented under a name given using the âdefâ keyword. In Python def 6 min read Python del keyword The del keyword in Python is used to delete objects like variables, lists, dictionary entries, or slices of a list. Since everything in Python is an object, del helps remove references to these objects and can free up memorydel Keyword removes the reference to an object. If that object has no other 2 min read Like