Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize multiple assignment by python

Shulou Source: shulou.com Published: 2022-06-01 05:26:54 09月12日 Update

Editor to share with you how to achieve multiple assignments in python, I hope you will gain something after reading this article. Let's discuss it together.

Multiple assignment

Multiple assignments can be used when assigning values to several variables. With the same idiom, you can exchange two variables or two elements in the same list. This feature is closely related to the tuple unpacking that will be introduced later.

> > # instead of doing a = 8; b = 5 > a, b = 8,5 > print (fancia is {a}; b is {b}') an is 8; b is 5 > > # Swap two variables > a, bb = b, a > print (franka is {a}; b is {b}') an is 5 B is 8 > > # Swap the first and last elements in a list > numbers = [1,2,3,4,5] > > numbers [0], numbers [- 1] = numbers [- 1], numbers [0] > > numbers [5,2,3,4,1] after reading this article, I believe you have a certain understanding of "how to achieve multiple assignments in python". If you want to know more about it, welcome to follow the industry information channel. Thank you for your reading!

Tags: Two variables articles elements done more features knowledge industry information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MySQL NVidia Docker Redmi