Professional Documents
Culture Documents
Python
Escape Characters:
To insert characters that are illegal in a string, we use an escape character.
An escape character is a backslash(\) followed by the character you want to insert.
Example:\
You will get an error if you use double quotes inside a string that is surrounded by double quotes:
The escape character allows you to use double quotes when you normally would not be allowed:
\n = Newline feed
\t = Tab
\\ = Backslash
Python Conditional Operators:
Equals: a == b
Not Equals: a != b
Less than: a < b
Less than or equal to: a <= b
Greater than: a > b
Greater than or equal to: a >= b
Python Conditional Operators:
if b > a:
print("b is greater than a") # you will get an error
Python Control Flow:
● Syntax of an if statement
if some_condition:
# execute some code
Python Control Flow:
● Syntax of an if/else statement
if some_condition:
# execute some code
else:
# do something else
Python Control Flow:
● Syntax of an if/else statement
if some_condition:
# execute some code
elif some_other_condition:
# do something different
else:
# do something else
Python Control Flow:
● Syntax of an if/else statement
if some_condition:
# execute some code
elif some_other_condition:
# do something different
else:
# do something else
Python Control Flow:
● Nested If Statement
if some_condition:
# execute some code
if some_other_condition:
# do something different
else:
# do something else
else:
#execute something else
Loops:
WHILE LOOP
While Loop:
While loops will continue to execute a block of code while some
condition remains True.
● Syntax of a while loop
while some_boolean_condition:
#do something
While Loop:
● You can combine with an else if you want
while some_boolean_condition: #do
something
else:
#do something different
While Loop:
● Break Statement: It will stop the loop even if while
condition is true.