1/16
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Indentation
Used to declare a block. If the statements are on the same level of indentation, then they are on the same block.
Programming Statements
Running a block of code based on a particular decision.
if statement
Used to test a specific condition, if the condition is true, a block of code (if-block) will be executed.
if-else statement
If the condition in the if statement is false, it will execute the else statement.
elif statement
Checks multiple conditions and executes the block of code of the condition that evaluated to true. Optional like else and can contain multiple elif after an if.
Nested if
Allows the use of another if statements inside an if.
The for loop
Used for iterating on a sequence. A set of statements may be executed once for each item, tuple, set, etc. and does not require an indexing variable to set beforehand.
The break statement (for loop)
Can stop the loop before it has looped through all the items.
The continue statement (for loop)
Can stop the current iteration of the loop, and continue with the next.
The range() function
Returns a sequence of numbers from 0 and increments by 1, by default, and ends at a specified number.
Nested loop
A loop inside a loop. The inner loop will be executed once per iteration of the outer loop.
The pass statement
for loop cannot be empty.
The while loop
As long as the condition is true, it can execute a block of statements. It needs to define an indexing variable.
The break statement (while loop)
The loop can be stopped even if the while condition is still true.
The else statement (while loop)
Can run a block of code when the condition is no longer true.
The do-while loop
Can run at least once. Python does not have a built-in do-while loop but possible to emulate.
Ternary Operator or Conditional Operator
Tests if a condition is true or false and returns the corresponding value, all in one line of code.