• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Python » Python Condition Statement
Next →
← Prev

Python Condition Statement

By Dinesh Thakur

If Statement, it is also known as a condition statement. If Statement increases the functionality of a Python. The ability to use logic “if-then-else” in your program is one of the most fundamental aspects of programming. Python programming provides an easy way to tell your program what to do if something is true, and what to do if something is false.

1. Determine what conditions you want to test. Here we see some example of the use of the if statement. The first section defines two variables (a and b) to use with if statement. Then we use two statements to compare the two variables to see if one is bigger than the other.
2. Determine which events you want to occur if the statement is true.
3. Create an if statement using a test condition, and place the events that occur if the statement is true immediately after the if statement. Use a colon (:) to indicate the end of the if statement: if a<b print “a is small than b”.

Example Greatest Between Two Variables

a = 5
b = 6
if a < b:
     print ("a is small than b")
elif a > b:
   print("b is greater than a")
else:
   print("Both are same")

4. Think about; if you have more than one condition, that’s you want to test.
5. if you have more than one condition, you can use “else-if” to continue your if statement. In Python, the keyword “elif” is used as shorthand for “else-if”. The elif statement ends with a colon (:) elif a>b print “b is greater than a”.
6. You can use as many as “elif”, one after another, as you needed to satisfy your needs.
7. If all the sequence of events that you want to occur are false. Then if statement end with else statement with a colon (:) print “Both are same”.
8. The next we check if two items are equal or not. The operator for testing equality is == and the operator to test inequality is! =. Here are the examples.

Example if statements: equal or not equal        

if a == b:
   print("a is equal to b")
if a != b:
   print("a not equal to b")

Note: It is straightforward to know when to use == and =. We use == if something is equal, we use = if something is same, i.e., to assign a value to something.

9. Each IF statement can check multiple conditions with and/or. They are also called operators such as + or -.

Example if statements, using “and” and “or”

if a < b and a < c:
  print("a is less than b and c")
if a < b or a < c:
  print("a is less than b or c (or both)")

10. Python supports Boolean variables, but what are Boolean variables? Boolean variables can store True (True) or False value (False). A statement if it needs a true expression (True) or False (False) to be evaluated. Here are the examples.

IF Statement and Boolean types 
 # Boolean Data type. 
 a = True 
   if a: 
     print ("a is true") 
 Example operator not (No) 
 # How to use the not operator 
 if not (a): 
    print ("A is false")

You’ll also like:

  1. What is Python? | Introduction to Python Programming
  2. Python Features | Main Features of Python Programming Language
  3. Python Operators and Operands – Types of Operators in Python
  4. How to use if condition in excel
  5. MySql Null Condition in Java Servlet
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Python

Python Tutorials

  • Python - Home
  • Python - Features
  • Python - Installation
  • Python - Hello World
  • Python - Operators Types
  • Python - Data Types
  • Python - Variable Type
  • Python - Switch Case
  • Python - Line Structure
  • Python - String Variables
  • Python - Condition Statement
  • Python - if else Statement
  • Python - for-loop
  • Python - while loop
  • Python - Command Line
  • Python - Regular Expression

Python Collections Data Types

  • Python - List
  • Python - Sets
  • Python - Tuples
  • Python - Dictionary

Python Functions

  • Python - Functions
  • Python - String Functions
  • Python - Lambda Function
  • Python - map() Function

Python Object Oriented

  • Python - Oops Concepts
  • Python - File Handling
  • Python - Exception Handling
  • Python - Multithreading
  • Python - File I/O

Python Data Structure

  • Python - Linked List
  • Python - Bubble Sort
  • Python - Selection Sort
  • Python - Linear Search
  • Python - Binary Search

Python Programs

  • Python - Armstrong Number
  • Python - Leap Year Program
  • Python - Fibonacci Series
  • Python - Factorial Program

Other Links

  • Python - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW