Class 12 - Basic Coding in Python - 3
Class 12 - Basic Coding in Python - 3
strazvan@jnu.ac.kr
Conditional Statements (if - else)
Hit twice
Note the indentation
ENTER
1. Hello World
3.Booleans
5. Loops
Booleans represent one of two values: True or False.
Rules
• Almost any value is True if it has some content
• Any string is True, except empty strings
• Any number is True, except 0
• Any list, tuple, set, and dictionary are True, except empty ones
• False values for empty fields, such as (), [], {}, "", the number 0, and the value None
• The value False evaluates to False.
Booleans represent one of two values: True or False.
Rules
• False values for empty fields, such as (), [], {}, "", the number 0, and the value None
• The value False evaluates to False.
Booleans represent one of two values: True or False.
Note the double == sign to indicate mathematical equality, different than when using variables (=)
Booleans represent one of two values: True or False.
• in
• not in
Operator Precedence
Addition + and subtraction - have the same precedence: execute commands from left to right:
Conditional Statements (if)
• Equals: a == b
• Not Equals: a != b
• Python relies on indentation (whitespace at the beginning of a line) to define scope in the code.
If you have only one statement to execute, you can put it on the same line as the if statement.
Conditional Statements ( nested if)
• else: if the previous statements (using if or elif) are not TRUE, execute following command
• else can also be used without elif
Conditional Expressions
and
or
not
Conditional Expressions
Nested if:
if statements inside other if statements