Python: Tips-Swap values

How to swap variable values

When you want to swap the values of the variable ʻa: 100and the variableb: 20, you usually create the variable c, hold the value of ʻa in c, and then say ʻa. Swap the values of b`.

swap.py


a = 100
b = 20

easy_swap.py


#Multiple assignment
a, b = 100,20

#Value exchange
a, b = b, a

By the way, Ruby can do the same.

Recommended Posts

Python: Tips-Swap values
Swapping values in Python
Python
Python --Check type of values
[Python] Passing values during multiprocessing
Transfer parameter values in Python
[Python] How to swap array values
kafka python
Python basics ⑤
python + lottery 6
Python Summary
Built-in python
Python> dictionary> values ()> Get All Values by Using values ()
Python comprehension
Studying python
Python 2.7 Countdown
Python memorandum
Python FlowFishMaster
Python service
python tips
Python memo
ufo-> python (3)
Python comprehension
install python
Python Singleton
Python basics ④
Python Memorandum 2
python memo
Python Jinja2
[Introduction to Udemy Python 3 + Application] 10. Numerical values
Python increment
atCoder 173 Python
[Python] function
Python installation
python tips
Installing Python 3.4.3.
Try python
Python memo
Python iterative
Python algorithm
Python2 + word2vec
[Python] Variables
Python functions
Python sys.intern ()
Python tutorial
Python decimals
python underscore
Python summary
Start python
[Python] Sort
Note: Python
Python basics ③
python log
Python basics
[Scraping] Python scraping
Python update (2.6-> 2.7)
python memo
Python memorandum
Python # sort
ufo-> python
Python nslookup