Thursday, February 19, 2026

Python Tutorial for Beginners: Operators and Conditional Statements

In the previous chapter, we learned about Python syntax,variables, and data types. These basics help you install Python, run programs, and write code correctly to get the results you want. If you haven’t finished the previous tutorial, make sure to go back and complete it before moving on.

Why use Operators?

An operator is a symbol that allows us to perform operations on values. The values on which the operator works are called operands.
Example: 5 + 3
Here 5 and 3 are operand and "+" is operator. They are generally divided into three main categories

Arithmetic Operators (Math Operators)

There are multiple operators that come under arithmetic operators.
  1. (+) - Addition
  2. (-) - Subtraction
  3. (*) - Multiplication
  4. (/) - Division - gives the Quotient with decimal
  5. (//) - Floor Division - gives the Quotient without decimal part
  6. (%) - Modulus - gives the Remainder
  7. (**) - Power - square, cube etc.

Comparision Operators

These are used to compare values and give output in True/False.
  1. (==) Equal to 
  2. (!=) Not equal to
  3. (>) - Greater than
  4. (<) - Less than
  5. (>=) - Greater than or equal to
  6. (<=) - Less than or equal.

Logical Operators

Used to combine conditional statements and return True or False based on logical conditions.
  1. And - Returns True if both conditions are True.
  2. OR - Returns True if at least one condition is True.
  3. Not - Reverses the result (True becomes False, False becomes True).

What is Conditional Statement in Python?

Decision-making is an important part of programming. It allows a program to execute certain statements only when a specific condition is true. Conditional statements help programmers control the flow of execution in a program.

If Statement

This statement only run when the condition is True. While False condition skip the block.

If-else Statement

This statement is used to check two conditions. It ensures that only one block of code executes based on whether the condition is True or False.

If-elif-else Statement

This is used when there are more than two conditions to check. The interpreter checks each condition one by one, and when a particular condition becomes true, the corresponding code block is executed. The remaining conditions are skipped.

Nested Condition

When we use an if statement inside another if statement, it is called a nested condition. It is used when multiple conditions must be checked at the same time.

Practic these tasks:

Task 1:
Check number is Negative or Positive
Task 2:
Ask a Number and then answer is ODD or Even.
Use this code to ask a number: number = int(input("Type a Number: "))

Conclusion

Here I've shared another Python tutorial. If you haven't read the previous one, visit the home page or search for python tutorial.

Practice Your Code Below

🐍 Python Playground

No comments:

Post a Comment

Featured Post

What Is Artificial Intelligence (AI) ? – A Step-by-Step Guide

AI (Artificial Intelligence) is a rapidly growing technology in today's world, and you can see it whenever you browse or search for any ...