Example of the location of python implementation exchanging two list elements

  • 2021-07-01 07:59:23
  • OfStack

Verify as follows in IDLE:


>>> numbers = [5, 6, 7]

>>> i = 0

>>> numbers[i], numbers[i+1] = numbers[i+1], numbers[i]

>>> numbers

[6, 5, 7]

python can assign two variables at a time! Thank you!


Related articles: