Lecture 3 Conditional Statements and Loops in Python
Lecture 3 Conditional Statements and Loops in Python
Lecture Contents
• Control Structures
• Sequence Structures
• Decision Structures
• if Statement
• if else Statement
• elif Statement ( Chained Conditionals)
• Nested Conditionals
• Repetition Structures
• Loops
• for loop
• while loop
• Things to Remember :
• if is in lower case
• There is a colon after the Boolean expression
• Body of if should be indented
• Can contain a single or multiple statements in the body
• range()
• Creates a type of object called an iterable
• iterable
• An object that contains a sequence of values that can be iterated over
• Used in counter-controlled loops ( for loop for example)
• Syntax
• range( start, stop, step)
• By default , start=0 . It is an optional argument
• stop is required . Specifies the end point. Itself not included
• step specifies the increment. By default, it is 1
• Example
The pass statement is a useful tool for avoiding errors and for creating
placeholders for future code.