Assignments and changes in Python objects

Overview

I was sick with Python, so I tested it. For details, refer to the original article (https://qiita.com/yuta0801/items/f8690a6e129c594de5fb). (I just want to know the behavior, so I'm not interested in passing by reference. I'll study again next time.)

Contents

tmp.py


obj = {'arr': ['hoge']}
print(obj)

arr = obj['arr']
obj['arr'] = []

print(obj)
print(arr)

output


{'arr': ['hoge']}
{'arr': []}
['hoge']

Serpentine

tmp.py


obj = {'arr': ['hoge']}
print(obj)

arr = obj['arr']
arr.append('fuga')
print(obj)
print(arr)

obj['arr'] = []
print(obj)
print(arr)

output


{'arr': ['hoge']}
{'arr': ['hoge', 'fuga']}
['hoge', 'fuga']
{'arr': []}
['hoge', 'fuga']

I feel so much better

Recommended Posts

Assignments and changes in Python objects
About python objects and classes
About Python variables and objects
Equivalence of objects in Python
Stack and Queue in Python
Unittest and CI in Python
The simplest Python memo in Japan (classes and objects)
MIDI packages in Python midi and pretty_midi
perl objects and python class part 2.
Difference between == and is in python
View photos in Python and html
Sorting algorithm and implementation in Python
Manipulate files and folders in Python
About dtypes in Python and Cython
Check and move directories in Python
Ciphertext in Python: IND-CCA2 and RSA-OAEP
Hashing data in R and Python
6 ways to string objects in Python
Function synthesis and application in Python
Examine the object's class in python
perl objects and python class part 1.
Export and output files in Python
Reverse Hiragana and Katakana in Python2.7
Reading and writing text in Python
[GUI in Python] PyQt5-Menu and Toolbar-
Create and read messagepacks in Python
Overlapping regular expressions in Python and Java
Differences in authenticity between Python and JavaScript
Modules and packages in Python are "namespaces"
Avoid nested loops in PHP and Python
AM modulation and demodulation in Python Part 2
difference between statements (statements) and expressions (expressions) in Python
Eigenvalues and eigenvectors: Linear algebra in Python <7>
Implementation module "deque" in queue and Python
Line graphs and scale lines in python
Implement FIR filters in Python and C
Differences in syntax between Python and Java
Check and receive Serial port in Python (Port check)
Search and play YouTube videos in Python
Difference between @classmethod and @staticmethod in Python
Difference between append and + = in Python list
Difference between nonlocal and global in Python
Write O_SYNC file in C and Python
Dealing with "years and months" in Python
Read and write JSON files in Python
Easily graph data in shell and Python
Private methods and fields in python [encryption]
Find and check inverse matrix in Python
Linear Independence and Basis: Linear Algebra in Python <6>
Call sudo in Python and autofill password
Differences in multithreading between Python and Jython
Module import and exception handling in python
How to use is and == in Python
Project Euler # 1 "Multiples of 3 and 5" in Python
Quadtree in Python --2
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python