Python: Control Statements
In this article, we take a look at the major control statements in Python. Primary we look at the control statements if-elif-else, for,while and control exit statement break . We list sample code for each of these and use in-line comments to explain what the code line does. Note that we declare the same functions in a class to adhere to object-oriented semantics. You can easily copy/paste the code in your Python code. if-elif-else statement class DemoClass: def IfThenElse(self): # Using integer inp = int(input("Enter a number: ")) if inp The output for the above code is: Sum is :3 Enter a number: 12 Number is positive Enter your name: Chaitanya You are nobody ! for loop class DemoClass: def ForLoop(self): # Print values from 0 to 5 for value in range(6): print(value) # Print values from 1 to 5 for value in range(1,6): print(value) # Print values from 1 to 5, step of 2...