CHAPTER 18 •
PYTHON
Python Else
Learn how to execute alternative code.
01 What is this?
Learn how to execute alternative code.
02 Syntax
Python Syntax
if condition:
statement
else:
statement
03 Example
Python Example
age = 16
if age >= 18:
print('Adult')
else:
print('Minor')
04 Important Points
Else executes when the if condition is false.
05 Common Mistakes
Maintain correct indentation.
06 Real World Use
Else is useful when there are two possible outcomes.
07 Practice This Topic
Now try the example yourself in the AIFA Python Editor.
- Read the example carefully.
- Change the values.
- Run the code.
- Observe the output.
- Try creating your own example.