Python Operators Easy Examples Every Beginner Must Know (2026)

0
Python Operators Easy Examples Every Beginner Must Know (2026)
Python Operators Easy Examples Every Beginner Must Know (2026)

📑 Table of Contents

Operators Definition in Python

Python Operators: Operator is a special symbol it can be used to perform logical or mathematical operations performed on data or variables. Operators in python can be used every programming languages because operators is process of our data and provide accurate results.

Types of Operators in Python with Example

  • Arithmetic Operators in Python
  • Relational Operators in Python
  • Logical Operators in Python
  • Assignment Operators in Python
  • Bitwise Operators in Python
  • Ternary Operators in Python
  • Membership Operators in Python
  • Identity Operators in Python

Arithmetic Operators in Python with Example Program

Arithmetic Operator: In this operator can be used to mathematical operation perform like addition, subtraction, multiplication division etc. It can be very most important operator in our python programming languages.

Types of Arithmetic Operators in Python

SymbolsOperationExample
    (+)Addition(a+b)=> (5+6)=>9
    (-)Subtraction(a-b)=> (8-3)=>5
    (*)Multiplication(a*b)=> (5*6)=>30
    (/)Division(a/b)=> (5/2)=>2.5
   (%)Modulus(a%b)=> (5%2)=>1

Python Arithmetic Operators Example

a=int(input("Enter First Number:"))
b=int(input("Enter Second Number:"))
print("Addition of a+b:",a+b);
print("Subtraction of a-b:",a-b);
print("Multiply of a*b:",a*b);
print("Division of a/b:",a/b);
print("Modulus of a%b:",a%b);
============OUTPUT============
Enter First Number: 5
Enter Second Number: 2
Addition of a+b: 7
Subtraction of a-b:3
Multiply of a*b:10
Division of a/b:2.5
Modulus of a%b:1

Conditional Operators in Python with Example

Conditional Operator: A conditional operators can be used to performed operation two values compression and results provide true and false. Conditional operators compare two variables expression and check relationship than provide results.

Types of Conditional Operator in Python

SymbolsOperationExample
    (==)Equal To(a==b)
    (>)Greater Than(a>b)
    (<)Less Than(a<b)
    (>=)Greater Than Or Equal To(a>=b)
   (<=)Less Than Or Equal To(a<=b)
   (!=)Not Equal To(a!=b)

Conditional Operator Example in Python

a=int(input("Enter First Number:"))
b=int(input("Enter Second Number:"))
print("Equal To a==b:",(a==b))
print("Greater Than a>b:",(a>b))
print("Less Than a<b:",(a<b))
print("Greater Than or Equal To a>=b:",(a>=b))
print("Less Than or Equal To a<=b:",(a<=b))
print("Not Equal To a!=b:",(a!=b))
============OUTPUT============
Enter First Number: 5
Enter Second Number: 2
Equal To a==b: False
Greater Than a>b: True
Less Than a<b: False
Greater Than or Equal To a>=b: True
Less Than or Equal To a<=b: False
Not Equal To: True

Logical Operators in Python with Example

Logical Operator: A logical operators can be used compare two variables and perform logical operations. If the logical condition is true than return 1 and logical condition is false than return 0.


Logical AND Operator: A logical and operator condition is a both condition are true than result are true. If the any one condition are false then return false.

Logical Operator in Python Program

username="jiocoding"
password="12345"
user=input("Enter Username:")
pwd=input("Enter Password:")
if(username==user and password==pwd):
        print("Login Successfully")
else:
        print("Username or Password Invalid")
============OUTPUT============
Enter Username: jiocoding
Enter Password: 12345
Login Successfully


Logical OR Operator: A logical or operator can be used to anyone condition are true than both condition are true. If one condition are false than return true.

Logical or Boolean Operators in Python

username="jiocoding"
password="12345"
user=input("Enter Username:")
pwd=input("Enter Password:")
if(username==user or password==pwd):
        print("Login Successfully")
else:
        print("Username or Password Invalid")

============OUTPUT============
Enter Username: jiocoding
Enter Password: 12345654
Login Successfully


Logical NOT Operator: A logical NOT operator reverses the state means if the condition is true it returns false and if the condition is false it returns true.

Types of Logical Operators in Python

SymbolsOperationExample
    (and)Logical and(a and b)
    (or)Logical or(a or b)
    (not)Logical not(a!=b)

Logical Operators in Python Program

username="jiocoding"
password="12345"
user=input("Enter Username:")
pwd=input("Enter Password:")
if(username==user and password==pwd):
        print("Login Successfully")
else:
        print("Username or Password Invalid")

============OUTPUT============
Enter Username: JIOCODING
Enter Password: 12345
Username or Password Invalid


Assignment Operator in Python with Example

Assignment Operator: A assignment operator can be used to assign the value of an right side and variable on the left side. 

Types of Assignment Operators in Python

SymbolsOperationExample
    (=)(a=b)(a=b)
    (+=)(a+=b)(a=a+b)
    (-=)(a-=b)(a=a-b)
    (*=)(a*=b)(a=a*b)
   (/=)(a/=b)(a=a/b)
   (%=)(a%=b)(a=a%b)

Assignment Operators in Python Example Program

a=int(input("Enter First Number:"))
b=int(input("Enter Second Number:"))
a+=b
print("Assignment Addition of a+=b:",a)

============OUTPUT============
Enter First Number: 8
Enter Second Number: 5
Assignment Addition of a+=b: 13

Bitwise Operators in Python with Example

Bitwise Operator: A bitwise operator can be used to perform individual operation bits on integers data. Bitwise operators are used to binary operations performed.

Types of Bitwise Operator in Python

SymbolsOperationExample
    (&)Bitwise AND(a&b)
    (|)Bitwise OR(a|b)
    (<<)Bitwise Shift Left(a<<b)
    (>>)Bitwise Shift Right(a>>b)

Bitwise Operators Example in Python

a=int(input("Enter First Number:"))
b=int(input("Enter Second Number:"))

print("Bitwise AND operator:",(a&b))
print("Bitwise OR operator:",(a|b))
print("Bitwise Shift Left Operator:",(a<<2))
print("Bitwise Shift Right Operator:",(a>>2))
============OUTPUT============
Enter First Number: 5
Enter Second Number: 3
Bitwise AND Operator: 1
Bitwise OR Operator:7
Bitwise Shift Left Operator: 20
Bitwise Shift Right Operator:1


Python Ternary Operator

Ternary Operators: A conditional operators can be used to one line operators or ternary operators because it can be used to three operands values.

Ternary Operators in Python Program

marks=70
res="Pass" if marks>=50 else "Fails"
print("Student Result:",res
)
============OUTPUT============
Student Result: Pass

Membership Operator Example in Python

Membership operator: Membership operator in Python is used to test whether a value or variable is found in a sequence (such as a string, list, tuple, or dictionary). The two membership operators are `in` and `not in`.

Membership Operators in Python

OperatorsDescriptions
    (in)Returns true if it finds specified element in sequence otherwise returns false.
    (not in)Returns true if it does not find specified element in sequence otherwise returns false.

Membership Operators in Python Program

data = ["Welcome","Jiocoding","Website","for","Learning","Python"]
if "Jiocoding" in data:
        print("Jiocoding is in the list") 

============OUTPUT============
Jiocoding is in the list


Membership Operators Not in Python Program

data = ["Welcome","Jiocoding","Website","For","Learning","Python"]
if "Java" not in data:
        print("Java is not in the list") 

============OUTPUT============
Java is not in the list

Identity Operator in Python

identity operator in python is represented by the keyword `is`. It is used to compare the memory locations of two objects to determine if they are the same object. Here is an example of how to use the `is` operator in Python.

OperatorsDescriptions
    (is)It returns true if both variables are the same object otherwise returns false.
    (is not)It returns true if both variables are not the same object otherwise returns false.

Identity Operators is Python Program

data = ["Welcome","Jiocoding","Website","for","Learning","Python"]
data2 = ["Welcome","Learning","Python"]
print(data1 is data2) 
============OUTPUT============
False

Identity Operators is Not Python Program

data = ["Welcome","Jiocoding","Website","for","Learning","Python"]
data2 = ["Welcome","Learning","Python"]
print(data1 is not data2) 
============OUTPUT============
True

Conclusion of Operators in Python Programming

Conclusion: A python operators can be used mathematical logical operations performed on data variables. I can explain everyone operators including with example if your any query or operator related questions than you can contact me by email or comment.


Post a Comment

0 Comments
Post a Comment (0)
To Top