EmSAT Achieve Exam  >  EmSAT Achieve Notes  >  Python for EmSAT Achieve  >  Operators in Python

Operators in Python | Python for EmSAT Achieve PDF Download

Introduction

In Python, operators are symbols that perform various operations on variables or values. They allow you to manipulate data and perform calculations. Understanding operators is essential for writing effective and efficient Python code. In this article, we will explore different types of operators in Python, along with examples and explanations.

Arithmetic Operators

Arithmetic operators are used to perform basic mathematical operations. Here are the commonly used arithmetic operators in Python:

  • Addition (+): Adds two operands.
  • Subtraction (-): Subtracts the second operand from the first.
  • Multiplication (*): Multiplies two operands.
  • Division (/): Divides the first operand by the second (result is always a float).
  • Floor Division (//): Divides the first operand by the second and returns the largest integer less than or equal to the quotient.
  • Modulus (%): Returns the remainder when the first operand is divided by the second.
  • Exponentiation (**): Raises the first operand to the power of the second.

Let's see some examples:

x = 10

y = 3

# Addition

print(x + y)  # Output: 13

# Subtraction

print(x - y)  # Output: 7

# Multiplication

print(x * y)  # Output: 30

# Division

print(x / y)  # Output: 3.3333333333333335

# Floor Division

print(x // y)  # Output: 3

# Modulus

print(x % y)  # Output: 1

# Exponentiation

print(x ** y)  # Output: 1000

Comparison Operators

Comparison operators are used to compare two values. They return a Boolean value (True or False) based on the comparison result. Here are the comparison operators in Python:

  • Equal to (==): Checks if the operands are equal.
  • Not equal to (!=): Checks if the operands are not equal.
  • Greater than (>): Checks if the left operand is greater than the right.
  • Less than (<): Checks if the left operand is less than the right.
  • Greater than or equal to (>=): Checks if the left operand is greater than or equal to the right.
  • Less than or equal to (<=): Checks if the left operand is less than or equal to the right.

Let's see some examples:

x = 5

y = 10

# Equal to

print(x == y)  # Output: False

# Not equal to

print(x != y)  # Output: True

# Greater than

print(x > y)  # Output: False

# Less than

print(x < y)  # Output: True

# Greater than or equal to

print(x >= y)  # Output: False

# Less than or equal to

print(x <= y)  # Output: True

Logical Operators

Logical operators are used to combine multiple conditions and perform logical operations. They return a Boolean value based on the evaluation result. Here are the logical operators in Python:

  • Logical AND (and): Returns True if both operands are True.
  • Logical OR (or): Returns True if at least one of the operands is True.
  • Logical NOT (not): Reverses the logical state of the operand.

Let's see some examples:

x = 5

y = 10

z = 3

# Logical AND

print(x < y and y < z)  # Output: False

# Logical OR

print(x < y or y < z)  # Output: True

# Logical NOT

print(not x < y)  #

The document Operators in Python | Python for EmSAT Achieve is a part of the EmSAT Achieve Course Python for EmSAT Achieve.
All you need of EmSAT Achieve at this link: EmSAT Achieve
49 videos|38 docs|18 tests

Top Courses for EmSAT Achieve

49 videos|38 docs|18 tests
Download as PDF
Explore Courses for EmSAT Achieve exam

Top Courses for EmSAT Achieve

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Operators in Python | Python for EmSAT Achieve

,

Semester Notes

,

Viva Questions

,

mock tests for examination

,

shortcuts and tricks

,

study material

,

video lectures

,

past year papers

,

Extra Questions

,

Summary

,

Previous Year Questions with Solutions

,

MCQs

,

ppt

,

practice quizzes

,

Objective type Questions

,

Operators in Python | Python for EmSAT Achieve

,

Free

,

Operators in Python | Python for EmSAT Achieve

,

pdf

,

Exam

,

Important questions

,

Sample Paper

;