Python Note: The mystery of assigning a variable to a variable

For example, like this. Numerical values and character strings produce the expected results.

####Numerical value####
num = 1
ber = num
num += 1
print(num)  # 2
print(ber)  # 1

####String####
te = "a"
xt = te
te += "b"
print(te)  # ab
print(xt)  # a

But with an array,

####Array####
li = [1,2]
st = li
li.append(3)
st.append(4)
print(li)  # [1,2,3,4]
print(st)  # [1,2,3,4]

** If you update one, the other is also updated, so you can see that they are the same object. ** ** So what the above st = li means is that the object named li can now also be referenced by the name` `st. It's just that (I don't know if you need to do that).

Recommended Posts

Python Note: The mystery of assigning a variable to a variable
How to check the memory size of a variable in Python
[python] A note that started to understand the behavior of matplotlib.pyplot
A note about the python version of python virtualenv
Python Note: When assigning a value to a string
[Note] Import of a file in the parent directory in Python
How to determine the existence of a selenium element in Python
A story that struggled to handle the Python package of PocketSphinx
How to check the memory size of a dictionary in Python
[Python3] Define a decorator to measure the execution time of a function
[python] [meta] Is the type of python a type?
The story of blackjack A processing (python)
Python Note: The secret role of commas
[Python] A simple function to find the center coordinates of a circle
[Python] A program that rotates the contents of the list to the left
[Python] The role of the asterisk in front of the variable. Divide the input value and assign it to a variable
Have Alexa run Python to give you a sense of the future
[Python] A program that calculates the number of socks to be paired
Python Note: When you want to know the attributes of an object
[Introduction to Python] How to sort the contents of a list efficiently with list sort
Python code to determine the monthly signal of a relative strength investment
I made a program to check the size of a file in Python
Python: I want to measure the processing time of a function neatly
[Python] Note: A self-made function that finds the area of the normal distribution
I made a function to see the movement of a two-dimensional array (Python)
How to calculate the volatility of a brand
How to embed a variable in a python string
[Note] Export the html of the site with python.
Make a copy of the list in Python
[Note] About the role of underscore "_" in Python
[Python] A rough understanding of the logging module
A discussion of the strengths and weaknesses of Python
[Python] Throw a message to the slack channel
the zen of Python
Note to daemonize python
Various ways to read the last line of a csv file in Python
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
[python] How to sort by the Nth Mth element of a multidimensional array
Build a python environment to learn the theory and implementation of deep learning
Python script to get a list of input examples for the AtCoder contest
Note: How to get the last day of the month with python (added the first day of the month)
I made a script to record the active window using win32gui of Python
How to get a list of files in the same directory with python
[Introduction to Python] How to get the index of data with a for statement
python beginners tried to predict the number of criminals
The wall of changing the Django service from Python 2.7 to Python 3
How to get the variable name itself in python
[Python] A program that counts the number of valleys
Get the variable name of the variable as a character string.
A memo connected to HiveServer2 of EMR with python
Template of python script to read the contents of the file
How to get the number of digits in Python
A memo to visually understand the axis of pandas.Panel
Note assigning image textures to materials in Maya python
Cut a part of the string using a Python slice
[python] option to turn off the output of click.progressbar
How to write a list / dictionary type of Python3
Make a note of the list of basic Pandas usage
A python implementation of the Bayesian linear regression class
Python points from the perspective of a C programmer
Things to note when initializing a list in Python