当前位置:网站首页>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)
边栏推荐
- Process scheduling and termination
- 使用druid连接MySQL数据库报类型错误
- RichView TRVStyle MainRVStyle
- Using druid to connect to MySQL database reports the wrong type
- Use the difference between "Chmod a + X" and "Chmod 755" [closed] - difference between using "Chmod a + X" and "Chmod 755" [closed]
- He was laid off.. 39 year old Ali P9, saved 150million
- 丸子百度小程序详细配置教程,审核通过。
- ASP. Net core 6 framework unveiling example demonstration [01]: initial programming experience
- RichView TRVStyle MainRVStyle
- Learn tla+ (XII) -- functions through examples
猜你喜欢

Tucson will lose more than $400million in the next year

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

【LeetCode】404. Sum of left leaves (2 brushes of wrong questions)
![[download white paper] does your customer relationship management (CRM) really](/img/e3/f130d071afb7309fdbf8a9c65b1d38.jpg)
[download white paper] does your customer relationship management (CRM) really "manage" customers?
![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

Visual explanation of Newton iteration method

Yolov5 model training and detection

Security level

Marubeni Baidu applet detailed configuration tutorial, approved.

Missile interception -- UPC winter vacation training match
随机推荐
Missile interception -- UPC winter vacation training match
Process scheduling and termination
Redis distributed lock, lock code logic
openresty ngx_ Lua execution phase
STM32 series - serial port UART software pin internal pull-up or external resistance pull-up - cause problem search
openresty ngx_lua執行階段
ASP. Net core 6 framework unveiling example demonstration [01]: initial programming experience
Vulnstack3
如何搭建一支搞垮公司的技术团队?
Practical case of SQL optimization: speed up your database
Erreur de type de datagramme MySQL en utilisant Druid
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
JVM's responsibility - load and run bytecode
Openresty ngx Lua Execution stage
Summary and practice of knowledge map construction technology
The MySQL team development specifications used by various factories are too detailed. It is recommended to collect them!
PowerShell: use PowerShell behind the proxy server
Talk about the things that must be paid attention to when interviewing programmers
Stored procedure and stored function in Oracle
Word processing software