if-else in Python


If block contains the condition, if condition is true, then the statements of if block will execute and if the condition is false then the statement of else block will execute.

Syntax :

if expression:
   statement(s) # statements must be indented 
else:
   statement(s) # statements must be indented 

Block Diagram :

prowessapps.in

Example:

WAP to check no. is +ive or -ive.
v = 5

if v >= 0:
    print("Number is positive or Zero")
else:
    print("Number is negative")

# Try for these values 
# v = -5
# v = 0
OUTPUT
Number is positive or Zero

Next topic is if-elif-else in Python





 







Training For College Campus

We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.

Please mail your requirement at info@prowessapps.in


Projects For Students

Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.

Students can mail requirement at info@prowessapps.in


CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-8527238801 , +91-9451396824

© 2017, prowessapps.in, All rights reserved