当前位置:网站首页>tuple and point
tuple and point
2022-07-05 02:24:00 【Incoming brother】
Tuples
About tuples : Tuples are in Python of use () Express , Unlike lists, tuples cannot be modified
If the tuple has only one value , We can't just write a value , This will turn Python The interpreter is confused
We're going to write ( value ,) Form like this
The purpose of tuples is to tell people who read code , You don't want to change this thing
hello = [1,2,3]
hello[1] = 4
# Wrong writing
tuple() and list()
We can convert tuple type to list type , You can also convert a list type to a tuple type
a = tuple([1,2,4])
print(type(a))
# Output is tuple type
a = list((1,2,3,4))
print(tupe(a))
# Output is list type
About quoting
Before you know about references , Let's compare the two programs first
a = 1
b = a
b = 2
print(a) #1
print(b) #2
We found this a The value of
a = [1,2,3]
b = a
b[0] = 0
print(a) # [0,2,3]
print(b) # [0,2,3]
We found out here a[1] The value of has changed , Mainly because of a It's a reference ,a Point to the list
b = a, It means to make b Also points to the list
Pass on references
def add(p):
a.append(4)
a = [1,2,3]
add(p)
print(a)
# [1,2,3,4]
This happens to lists and dictionaries
If you don't want this quote to happen , You can use full assignment
import copy
a = [1,2,3,4]
b = copy.copy(a)
b[1] = 0
print(a) #[1,2,3,4]
print(b) #[0,2,3,4]
print('========')
# If a list is nested in the list
c = [1,[1,2,3]]
d = copy.deepcopy(c)
d[1] = 0
print(c)
print(d)
summary :
1). The list is variable , Tuples are immutable
2). The assignment of a list is a reference
3). The complete assignment is copy.copy(list),copy.deepcopy(list)
边栏推荐
- JVM - when multiple threads initialize the same class, only one thread is allowed to initialize
- Leetcode takes out the least number of magic beans
- Li Kou Jianzhi offer -- binary tree chapter
- Talk about the things that must be paid attention to when interviewing programmers
- Action News
- Win: use PowerShell to check the strength of wireless signal
- Unpool(nn.MaxUnpool2d)
- Abacus mental arithmetic test
- One plus six brushes into Kali nethunter
- 力扣剑指offer——二叉树篇
猜你喜欢

Security level

Yolov5 model training and detection

The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety

Visual explanation of Newton iteration method
![Hmi-31- [motion mode] solve the problem of picture display of music module](/img/9c/0b25c0a41758652848aed2a269880f.jpg)
Hmi-31- [motion mode] solve the problem of picture display of music module

【LeetCode】501. Mode in binary search tree (2 wrong questions)

Exploration of short text analysis in the field of medical and health (I)

runc hang 导致 Kubernetes 节点 NotReady

. Net starts again happy 20th birthday
![Hmi-30- [motion mode] the module on the right side of the instrument starts to write](/img/6b/09bb8fd95b707a459534eaeb72eb59.jpg)
Hmi-30- [motion mode] the module on the right side of the instrument starts to write
随机推荐
A label making navigation bar
Design and practice of kubernetes cluster and application monitoring scheme
. Net starts again happy 20th birthday
低度酒赛道进入洗牌期,新品牌如何破局三大难题?
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Win: enable and disable USB drives using group policy
Interpretation of mask RCNN paper
Missile interception -- UPC winter vacation training match
丸子百度小程序详细配置教程,审核通过。
The application and Optimization Practice of redis in vivo push platform is transferred to the end of metadata by
[機緣參悟-38]:鬼穀子-第五飛箝篇 - 警示之一:有一種殺稱為“捧殺”
Talk about the things that must be paid attention to when interviewing programmers
RichView TRVStyle MainRVStyle
Official announcement! The third cloud native programming challenge is officially launched!
Yolov5 model training and detection
Numpy library introductory tutorial: basic knowledge summary
Action News
[download white paper] does your customer relationship management (CRM) really "manage" customers?
openresty ngx_lua執行階段
Runc hang causes the kubernetes node notready