• Free Python 3 Tutorial
  • Control Flow
  • Exception Handling
  • Python Programs
  • Python Projects
  • Python Interview Questions
  • Python Database
  • Data Science With Python
  • Machine Learning with Python
  • One Liner for Python if-elif-else Statements
  • Break a long line into multiple lines in Python
  • How to Convert Bytes to String in Python ?
  • Highlight a Bar in Bar Chart using Altair in Python
  • Working with Images - Python .docx Module
  • Using Certbot Manually for SSL certificates
  • Upgrading from Python2 to Python3 on MacOS
  • When not to use Recursion while Programming in Python?
  • Working with Titles and Heading - Python docx Module
  • Working with Highlighted Text in Python .docx Module
  • Working with Page Break - Python .docx Module
  • Network Programming Python - HTTP Requests
  • Working with Headers And Footers in Python .docx Module
  • Working with Tables - Python .docx Module
  • Paragraph Formatting In Python .docx Module
  • Working With Text In Python .docx Module
  • How to Define an Auto Increment Primary Key in PostgreSQL using Python?
  • Securing Django Admin login with OTP (2 Factor Authentication)
  • How to clear Tkinter Canvas?

Assigning multiple variables in one line in Python

A variable is a segment of memory with a unique name used to hold data that will later be processed. Although each programming language has a different mechanism for declaring variables, the name and the data that will be assigned to each variable are always the same. They are capable of storing values of data types.

The assignment operator(=) assigns the value provided to its right to the variable name given to its left. Given is the basic syntax of variable declaration:

 Assign Values to Multiple Variables in One Line

Given above is the mechanism for assigning just variables in Python but it is possible to assign multiple variables at the same time. Python assigns values from right to left. When assigning multiple variables in a single line, different variable names are provided to the left of the assignment operator separated by a comma. The same goes for their respective values except they should be to the right of the assignment operator.

While declaring variables in this fashion one must be careful with the order of the names and their corresponding value first variable name to the left of the assignment operator is assigned with the first value to its right and so on. 

Variable assignment in a single line can also be done for different data types.

Not just simple variable assignment, assignment after performing some operation can also be done in the same way.

Assigning different operation results to multiple variable.

Here, we are storing different characters in a different variables.

Please Login to comment...

  • python-basics
  • Technical Scripter 2020
  • Technical Scripter
  • 10 Best Free Social Media Management and Marketing Apps for Android - 2024
  • 10 Best Customer Database Software of 2024
  • How to Delete Whatsapp Business Account?
  • Discord vs Zoom: Select The Efficienct One for Virtual Meetings?
  • 30 OOPs Interview Questions and Answers (2024)

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

IMAGES

  1. Tuple Assignment in Python

    double assignment in python

  2. Double Char In Python

    double assignment in python

  3. Python Tutorial 11

    double assignment in python

  4. Python Programming #2

    double assignment in python

  5. Program to swap two variables in python using assignment operator

    double assignment in python

  6. What is Multiple Assignment in Python and How to use it?

    double assignment in python

VIDEO

  1. Assignment

  2. double assignment in python #shorts

  3. UGANDA'S DOUBLE ASSIGNMENT : DAY 1 SESSION 1 OF THE LYATONDE SUBREGIONAL MISSIONARY TRAINING

  4. Week 3 graded assignment python #python #iitm

  5. Assignment

  6. Add Two Numbers II

COMMENTS

  1. The Walrus Operator: Python 3.8 Assignment Expressions

    For Python 3.8, the biggest change is the addition of assignment expressions. Specifically, the := operator gives you a new syntax for assigning variables in the middle of expressions. This operator is colloquially known as the walrus operator. This tutorial is an in-depth introduction to the walrus operator.

  2. Assigning multiple variables in one line in Python

    Python assigns values from right to left. When assigning multiple variables in a single line, different variable names are provided to the left of the assignment operator separated by a comma. The same goes for their respective values except they should be to the right of the assignment operator. While declaring variables in this fashion one ...

  3. Python's Assignment Operator: Write Robust Assignments

    To create a new variable or to update the value of an existing one in Python, you’ll use an assignment statement. This statement has the following three components: A left operand, which must be a variable. The assignment operator ( =) A right operand, which can be a concrete value, an object, or an expression.