Skip to content

Latest commit

 

History

History
38 lines (22 loc) · 1.38 KB

File metadata and controls

38 lines (22 loc) · 1.38 KB

Assignment Operations in Python

Introduction

Assignment operators in Python are used to assign values to variables. They include the basic assignment operator (=) and various compound assignment operators that perform an operation on the variable while assigning a value.

List of Assignment Operators

  1. Basic Assignment (=): Assigns a value to a variable.

  2. Addition Assignment (+=): Adds the right operand to the left operand and assigns the result to the left operand.

  3. Subtraction Assignment (-=): Subtracts the right operand from the left operand and assigns the result to the left operand.

  4. Multiplication Assignment (*=): Multiplies the left operand by the right operand and assigns the result to the left operand.

  5. Division Assignment (/=): Divides the left operand by the right operand and assigns the result to the left operand.

  6. Floor Division Assignment (//=): Performs floor division on the left operand and assigns the result to the left operand.

  7. Modulus Assignment (%=): Calculates the modulus of the left operand and assigns the result to the left operand.

  8. Exponentiation Assignment (=):** Raises the left operand to the power of the right operand and assigns the result to the left operand.

Examples

Basic Assignment

x = 5

Addition Assignment

y = 10
y += 3  # Equivalent to y = y + 3