Sequencing & Selection (If & switch statements)

Fill in the blanks

In Python, the statement is used for conditional execution of code. It allows you to specify a block of code that will be executed only if a certain is met. The basic syntax of an if statement in Python is as follows: if condition: # indented code to be executed if the condition is True. You can also include an else block to specify code that should be executed when the is not met.



The if-elif-else statement is used when you have multiple conditions to check in a sequence. It allows you to test each one by one, and as soon as one of the conditions is satisfied, the corresponding block of code will be executed. This is known as a if. Nested if statements are used when you have an if statement inside another if statement, which allows you to create more conditions and control flows.



Switch statements are a really useful tool for structured pattern matching. From Python 3.10 onwards, it is supported using the match-case statement. Each case constant is compared against the value. Upon finding a match, the corresponding code block is executed until a break statement is encountered. If none of the cases match the value, the code within the _ case is executed. Before Python 3.10, programmers had to emulate a switch statement using if statements, which consisted of checking each case with elif and providing a default case at the end using else.

Keywords

expression | condition | condition | condition | expression | chained | complex | if |