Short Circuiting Techniques in Python
In this tutorial, we are going to learn the techniques used for short-circuiting in Python. Basically short-circuiting means that the stoppage of the Boolean expression.
In this technique evaluation of expression takes place from left to right.
In Python programming language short-circuiting is supported by the help of many boolean expressions.
Operators like: conditional operators also support short-circuiting and when the result has obtained no further execution will take place.
In this, you can use Functions and Boolean operators. Operations used to determine the short-circuiting.
The operations given below has some meanings like:
1.OR operation: if x is false then y will be executed only and if x is true then x will be executed.
2. AND operation: if x is true then y is going to executed and if x is false then x will get executed.
These are the main operations we use in this program because they both are the most usable operations for the short-circuiting techniques in a Python programming language. They are the best method to calculate short-circuiting.
* Example for OR operation:
x = 2>0 if x or 2 / 0 ==0: print("true") else: print("false")
Output = true
* Example for AND operation
x = 3<0 if (x and 3 / 0 == 0): print("true") else: print("false")
Output = false
Also read: Decimal functions in Python