Course Content
What is Python?
Introduction of Python and Its setup
0/2
Control Statement
Control statements are used to control the flow of execution depending upon the specified condition/logic.
0/4
File Handling
File handling is an important component of any application. Python has multiple functions for creating, reading, updating, and deleting files.
0/2
Examples
Following are the examples of python scripts to try hands-on, you are ready to start your python journey.
0/7
Python
About Lesson

Control statements are used to control the flow of execution depending upon the specified condition/logic.

1)if- Statement

An if statement is a programming conditional statement that, if the condition is true, it executes the block of code inside of it.

if- Statement

books = 2  
if (books == 2) :
   print(" You have")  
   print("Two books")  
print("Outside of if statement") 

In the above code, we are checking if books is equal to 2, then execute the given code.

2)if-else statement

The if-else statement executes some code if the test expression is true (non-zero) and some other code if the test expression is false.

if-else Statement

a=10  
if a<100:   
      print('less than 100')  
else:  
      print('more than equal 100')

In the above code, we are checking if a is less than 100, else will print “more than equal 100′.

 

3)Nested If-Else Statement

The nested if … else statement allows you to check for multiple test expressions and executes different codes for more than two conditions.

num = float(input("enter a number:"))  
if num >=0:  
     if num==0:  
         print("zero")  
else:  
     print("Negative number")  

In the above code, we are first checking if num is greater than or equal to 0 and then if it is zero if both the conditions are met, “zero” is printed, otherwise “Negative number”.