• Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials – Company wise
      • Infosys Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Dell Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • TCS Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation – E Books
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
      • Quant for Placements
    • Register
    • Login
  • [email protected]
  • ..
Login / Register
Apply Now
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
0

Cart

Operators in Python

  • January 24, 2020
  • CODE OF GEEKS
  • 0

An operator is a special symbol that is used to perform some operations in a Python program. An operator generally requires some variables, known as operands, to operate upon.

Python provides us with the number of operators.

Operators can be unary or ternary. Unary operator requires a single operand to operate upon. Ternary operator requires two or more operators to operate upon. Further moving on, we can classify operators into various parts :

  1. Arithmetic Operators
  2. Assignment Operators
  3. Relational Operators
  4. Logical Operators
  5. Bitwise Operators
  6. Membership Operators
  7. Identity Operators

1. Arithmetic Operators

num1 = 20
num2 = 10

# Working with Arithmetic Operators

print("num1 + num2 = ", num1+num2)
print("num1 - num2 = ", num1-num2)
print("num1 * num2 = ", num1*num2)
print("num1 / num2 = ", num1/num2)
print("num1 // num2 = ", num1//num2)
print("num1 % num2 = ", num1%num2)
print("num1 ** num2 = ", num1**num2)

2. Assignment Operators

# Working with Assignment Operators
num = 10
print("num = ", num)
num += 5
print("num += 5 = ", num)
num -= 5
print("num -= 5 = ", num)
num *= 5
print("num *= 5 = ", num)
num /= 5
print("num /= 5 = ", num)
num //= 5
print("num //= 5 = ", num)
num **= 5
print("num **= 5 = ", num)
num = 5
num &= 5
print("num &= 5 = ", num)
num |= 5
print("num |= 5 = ", num)

3. Relational/ Comparison Operator

num1 = 20
num2 = 10

# Working with Relational Operators

print("num1 < num2 = ", num1<num2)
print("num1 > num2 = ", num1>num2)
print("num1 == num2 = ", num1==num2)
print("num1 >= num2 = ", num1>=num2)
print("num1 <= num2 = ", num1<=num2)
print("num1 != num2 = ", num1!=num2)

4. Logical Operator

condition1 = False
condition2 = True

# Working with Logical Operators

print("condition1 and condition2 = ", condition1 and condition2)
print("condition1 or condition1 = ", condition1 or condition2)
print("not condition1 = ", not condition1)

5. Bitwise Operator

num1 = 20
num2 = 10

# Working with Bitwise Operators

print("num1 | num2 = ", num1|num2)
print("num1 ^ num2 = ", num1^num2)
print("num1 & num2 = ", num1&num2)
print("num1 << num2 = ", num1<<num2)
print("num1 >> num2 = ", num1>>num2)
print("~ num2 = ", ~num2)

6. Membership Operators

list1 = [2, 5, 6, 7]
n = 5
if n in list1:
    print("Number present in list")
elif n not in list1:
    print("Number not present in list")

7. Identity Operators

num1 = 10
num2 = 10
num3 = 20
if num1 is num2:
    print("num1 is num2")
if num1 is not num3:
    print("num1 is not num3")

That’s all, see you in the next lecture.



Tags: Arithmetic OperatorsArithmetic Operators pythonAssignment Operators in pythonAssignment Operators pythonBitwise Operators in pythonIdentity OperatorsIdentity Operators in pythonLogical Operators in pythonMembership OperatorsMembership Operators in pythonMembership Operators pythonoperators in pythonpython operatorsRelational Operators in python
  • Previous Python Mathematical Functions
  • Next SQL Query Interview Questions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Table of Content – Python

  1. Introduction to Python Programming
    • Python and its features
    • Key Differences : C vs Python
    • Key Differences : Java vs Python
    • Python Flavors
    • PVM and Memory Management in Python

  2. Python Programming Fundamentals
    • 'Hello World' using Python
    • Comments in Python
    • Variables and Garbage Collection in Python
    • Datatypes in Python
    • Determining the Datatype of Literal | type() method
    • Tokens in Python
    • Keywords in Python
    • Identifiers and Naming Convention in Python
    • Literals in Python

  3. Python Operators
    • Operators in Python
    • Python Mathematical Functions

  4. Python User Inputs
    • Taking Inputs | input() function in Python

  5. Python Control Statements
    • Control Statements in Python
    • If-elif-else Statements in Python
    • Looping in Python
    • while loop in Python
    • for loop in Python
    • Infinite loops in Python
    • Nested loops in Python
    • Break Statement in Python
    • Continue Statement in Python
CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Courses

  • Mail Us
  • Login/Register

Recent Posts

What is Amazon Web Services | AWS Regions & AZs | Different AWS Services
  • October 19, 2021
TCS Reasoning 2021
  • October 4, 2021

Copyright 2021 CODE OF GEEKS. All Rights Reserved.

  • →