0% found this document useful (0 votes)
6 views44 pages

Controlled Statement in Python

If-else

Uploaded by

Seema Bhartiya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views44 pages

Controlled Statement in Python

If-else

Uploaded by

Seema Bhartiya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

AND - if two conditions are true then both true

if 1 false then false


a=5
b=10

a=5 (assignment operator)


a==5(comparing operator)

X and Y to stand - so will teach


else not teach
both are standing is TRUE
OR - if two conditions are true then both true
if 1 false then TRUE
a=5
b=10

a=5 (assignment operator)


a==5(comparing operator)

X OR Y to stand - one student needs to stand then I will teach


both are TRUE
a=5 b=10

a==6 or b>=10
a==6 and b>=10
5==6 FALSE
5==6 and 10>=10
10>=10 True
False and True - FALSE
False or TRUE - then True
NOT is opposite
if False then true
if true then false
Example 2 + 3 * 4
In this example, the multiplication operator * has higher precedence than the addition operator +.
Therefore, the expression is evaluated as follows:1
. Evaluate the multiplication: 3 * 4 = 12
2. Evaluate the addition: 2 + 12 = 14
Example 2 + 3 + 4
In this example, the addition operators + have the same precedence.
Since addition is left-associative, the expression is evaluated as follows:
1. Evaluate the first addition: 2 + 3 = 5
2. Evaluate the second addition: 5 + 4 = 9
Mnemonic: Please Excuse My Dear Aunt Sally Relax Now And Often.

• Parenthesis: () - These always get done first, like they're the boss!
• Exponents: ** - Next in line, powerful operations.
• Multiplication: *,
• Division: /, Floor Division: //, Modulus: % - These have equal precedence and are done from left to right. Think
of them as equally important colleagues.

• Addition: +,
• Subtraction: - - Similar to multiplication and division, they have equal precedence and are done left to right.
• Relational operators: <, <=, >, >=, ==, != - These are comparisons, checking relationships.
• Not: not - This is a logical negation.
• And: and - Another logical operator.
• Or: or - The final logical operator.
Parentheses first, don't be slow,
Exponents next, watch them grow.
Multiplication and Division, a left-to-right show,
Addition and Subtraction, follow the flow.
Relations compare, it's true or it's not,
Not, And, then Or, the logical plot.

You might also like