1.6.1
Selection
If-statements
If-statements
If-statements are the only form of selection in Python.
If statements
If statements
- Conditions can be tested using the if statement. For example:
- if (x > 50):
- Any code written in an indented block after this line will be executed if the condition is true.
Else statements
Else statements
- We can also add an else statement to the end, for example:
- else:
- This will only execute the following indented block if the condition was false.
Elif statements
Elif statements
- Elif statements can be added between if and else blocks.
- They will execute if the condition before it was false, and the condition following it is true.
1Introduction to Python
1.1Python
1.2Input & Output
1.3Data Types
1.4Variables & Constants
1.6Program Flow
2Data Structures
2.1Lists & Strings
2.2File Handling
3Modularity
3.1Subroutines
3.2Data Flow
4Good Practice
4.1Naming & Whitespace
4.2Comments
4.3Exceptions
Jump to other topics
1Introduction to Python
1.1Python
1.2Input & Output
1.3Data Types
1.4Variables & Constants
1.6Program Flow
2Data Structures
2.1Lists & Strings
2.2File Handling
3Modularity
3.1Subroutines
3.2Data Flow
4Good Practice
4.1Naming & Whitespace
4.2Comments
4.3Exceptions
Unlock your full potential with GoStudent tutoring
Affordable 1:1 tutoring from the comfort of your home
Tutors are matched to your specific learning needs
30+ school subjects covered