GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • C programming
  • C++ programming
  • Java programming
  • Python programming
  • HTML
  • CSS
  • Codenora IDE (opens in a new tab)
  • About us
  • Pricing
  • Contact us
  • Privacy policy
  • Terms of service
  • Refund and Cancellation

This view

  • Original page
  • New address

GeezerVison is showing www.dremendo.com — Assignment Operators in Python Programming | Dremendo

  • Dremendo
  • C
  • C++
  • Java
  • Python
  • HTML
  • CSS
  • More
    • Home
    • C Tutorial
    • C++ Tutorial
    • Java Tutorial
    • Python Tutorial
    • HTML Tutorial
    • CSS Tutorial
?>
profile image
Announcements
No new announcements.
mentora icon
Python Programming Tutorial
  • Python Basic Concepts
    • Introduction
    • Variable
    • Data Types
    • Naming Conventions
    • Typecasting
  • Operators in Python
    • Operators
    • Assignment Operators
    • Arithmetic Operators
    • Relational Operators
    • Logical Operators
    • Identity Operators
    • Membership Operators
    • Operator Precedence
  • Input and Output in Python
    • Environment Setup
    • print() Function
    • input() Function
    • Comments
  • Decision Making in Python
    • Decision Making
    • if Statement
    • if else Statement
    • if elif Statement
  • Mathematical Functions
    • Mathematical Functions
  • Loops in Python
    • Loops
    • for Loop
    • while Loop
  • String in Python
    • String
    • String Methods
  • Built-in Data Structures in Python
    • Lists
    • Tuples
    • Sets
    • Dictionaries
  • Arrays in Python
    • Arrays
  • Searching in Python
    • Linear Search
    • Binary Search
  • Sorting in Python
    • Bubble Sort
    • Selection Sort
    • Insertion Sort
  • Function in Python
    • Function
    • Recursive Function
    • Lambda Function
    • Closures
    • Decorators
    • Generators
  • OOPs in Python
    • Classes and Objects
    • Instance Variables
    • Instance Methods
    • Class Variables
    • Static Methods
    • Inheritance
    • Types of Inheritance
    • MRO
    • Polymorphism
    • Abstract Classes
  • User-Defined Data Structures in Python
    • Stack
    • Queue
    • Circular Queue
    • Double Ended Queue
    • Singly Linked List
    • Doubly Linked List
    • Stack using Linked List
    • Queue using Linked List
  • Modules in Python
    • Modules
    • Time Module
    • Datetime Module
    • OS Module
    • Shutil Module
    • Sys Module
    • JSON Module
    • Random Module
  • Regular Expression in Python
    • Regular Expression
  • Exceptions in Python
    • Exception Handling
  • File Handling in Python
    • Text File Handling
    • Binary File Handling
    • CSV File Handling

bookmark
Table of Contents

    Assignment Operators in Python Programming

    In this lesson, we are going to look at what is assignment operator and will learn the different types of assignment operator with the help of examples.

    What is Assignment Operator

    Assignment Operator in Python is used for assigning value to a variable. Using the assignment operator we can assign the value which is on the right side of the operator to the variable on the left side of the operator.

    Video Explanation

    Click the button below to watch the explanation.

    Please wait while the video is loading....
    video image

    Let's discuss about the different types of assignment operators with examples.

    Assign Operator =

    The Assign Operator = is used to assign a value to a variable. It takes the value on its right-hand side and assigns it to the variable on its left-hand side.

    Example
    a=5    # value 5 is assigned to variable a
    b=a    # value of variable a which is 5 is assigned to the variable b

    As you can see the value 5 which is on the right side of the operator = has been assigned to the left in the variable a. In the same way value of the variable a (5) which is on the right side of the operator = has been assigned to the left in the variable b

    Add and Assign Operator +=

    The Add and Assign Operator += is a combination of + and = operators. This operator adds the value of the right-hand operand to the left-hand operand and then assigns the result back to the left-hand operand. It is a shorthand way to perform addition and assignment in a single step.

    Example
    a=2
    b=10
    c=5
    a+=2    # can be written as a=a+2 (a=2+2) result is a=4
    b+=c    # can be written as b=b+c (b=10+5) result is b=15

    Subtract and Assign Operator -=

    The Subtract and Assign Operator -= is a combination of - and = operators. This operator subtracts the value of the right-hand operand from the left-hand operand and then assigns the result back to the left-hand operand. It is a shorthand way to perform subtraction and assignment in a single step.

    Example
    a=6
    b=10
    c=5
    a-=2    # can be written as a=a-2 (a=6-2) result is a=4
    b-=c    # can be written as b=b-c (b=10-5) result is b=5

    Multiply and Assign Operator *=

    The *= operator is a combination of * and = operators. This operator multiplies the value of the left-hand operand by the right-hand operand and then assigns the result back to the left-hand operand. It is a shorthand way to perform multiplication and assignment in a single step.

    Example
    a=7
    b=10
    c=5
    a*=2    # can be written as a=a*2 (a=7*2) result is a=14
    b*=c    # can be written as b=b*c (b=10*5) result is b=50

    Divide and Assign Operator /=

    The /= operator is a combination of / and = operators. This operator divides the value of the left-hand operand by the right-hand operand and then assigns the result back to the left-hand operand. It is a shorthand way to perform division and assignment in a single step.

    Example
    a=18
    b=10
    c=5
    a/=2    # can be written as a=a/2 (a=18/2) result is a=9 (quotient)
    b/=c    # can be written as b=b/c (b=10/5) result is b=2 (quotient)

    Modulus and Assign Operator %=

    The %= operator is a combination of % and = operators. This operator calculates the remainder of the division of the left-hand operand by the right-hand operand and then assigns the result back to the left-hand operand. It is a shorthand way to perform modulus and assignment in a single step.

    Example
    a=6
    b=10
    c=8
    a%=2    # can be written as a=a%2 (a=6%2) result is a=0 (remainder)
    b%=c    # can be written as b=b%c (b=10%8) result is b=2 (remainder)

    Test Your Knowledge

    Attempt the questions in the exercise to check whether you have understood the lesson clearly.

    Exercise
    Test Your Knowledge
    Previous Next

    We care about your privacy

    Dremendo uses cookies and similar technologies that are necessary for the site to work properly, understand how you interact with our website, and measure the effectiveness of our marketing. By clicking Accept All, you consent to the use of non-essential cookies and similar technologies for analytics, advertising, and ad measurement, as described in our Privacy Policy.

    Cookie Preferences

    Choose which types of cookies Dremendo may use.

    Necessary Cookies

    Required for essential website functionality and security.

    Allow
    Analytics Cookies

    Help us understand how visitors use Dremendo.

    Allow
    Marketing Cookies

    Help us measure advertising performance and understand interactions with our advertisements.

    Allow
    Mentora Question Asked: 0 / 20

    Hi, I’m Mentora!

    I’m your personal AI tutor from Dremendo. Ask me anything, and I’ll help you understand it in a simple and easy way.

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.