Python Lecture 5
Python Lecture 5
(Python)
Control Statements
Learning Outcome
• if statements
• elif statements
• else statement
Indentation
• For the control flow in python we need to use indentation and colon
• Indentation makes the python to be different than other languages
• It is used to create blocks of code instead of bracket ( { } )
• Example:
elif, else
Practice
• Using if elif statements, print the number for the corresponding grade.
• To print from 2 to 5 :
• Start list[1:2]
• End
• Step
More examples
• Function range (num) can provide any number from 0 up to the range number-1.
• The range(starting, ending, step)
• for (int I =0; I < 5 ; I ++)
• Here we get number from zero up to 4
• Break:
• Breaks out the current loop and goes to the rest of the code
• Continue:
• Skips the rest of the current iteration and goes to the next one
• Pass:
• Does nothing, lets the interpreter to continue with code
Thank You!