GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||
GeezerVison is showing codescracker.com — Python or keyword
Python or keywordIf any of the expressions, statements, or operands evaluate to true, the "or" keyword returns True. For example: a = 50 b = 60 c = 70 d = 80 print(a>b or b>c or d>c) The output is: True Or is a logical operator that combines boolean expressions. The "or" keyword returns True if at least one of the expressions evaluates to True; otherwise, it returns False. The "or" keyword employs short-circuit evaluation, which means that if the first expression in a "or" expression evaluates to True, the second expression is not evaluated. The "or" keyword has lower precedence than comparison operators (such as ==, >, <), but higher precedence than "and." The "or" keyword returns the first value that is considered "True" in a boolean context when used with non-boolean values. If no value is considered "True", the last value will be returned. The "or" keyword may also be used in list comprehension and generator expressions. The "or" and "not" keywords can be combined to create more complex boolean expressions. The "or" keyword is available in all Python versions as part of the standard library. Common uses of the "or" keyword in programming include testing for multiple conditions simultaneously and assigning default values to variables. The truth table of the Python "or" keywordThe table given below shows the truth table of the Python "or" keyword:
Python "or" keyword exampleHere is an example of the Python "or" keyword: print(True or False) print(False or False) print(True or True) print(True or True or True or False or True or True) print(False or False or False or False or False) The output is: True False True True False Advantages of the "or" keyword in Python
Disadvantages of the "or" keyword in Python
« Previous Tutorial Next Tutorial » Practice Quizzes
Test your programming and computer science knowledge with interactive MCQs and topic-based quizzes. Popular Topics
Explore the most popular programming and computer science tutorials on CodesCracker. | |||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |