当前位置:网站首页>Tuples of combined data types
Tuples of combined data types
2022-06-29 02:18:00 【Long street 395】
describe
This is one about " Tuples of combined data types " My little exercises , Override the base of tuple types 、 The operator 、 Use of functions and methods, etc , There are two parts : Follow practice and quiz .
stay " Follow practice " link , Please use IDLE The interaction mode of the editor , Enter the following statements one by one , Observe and compare the output .
stay " quiz " link , Please fill in the corresponding " Submission code " Enter the code on the page as required ," Save and submit comments " Check the results after .
Follow practice
Please use IDLE The interaction mode of the editor ( contain >>> Prompt ), Enter the following statements one by one in order ( common 20 individual ):
>>>t = 1, 2, 3, 2, 1
>>>max(t)
3
>>>t.index(1)
0
>>>t.count(1)
2
>>>s = (1, "a", 2, "b")
>>>min(s)
Traceback (most recent call last):
File "<pyshell#49>", line 1, in <module>
min(s)
TypeError: unorderable types: str() < int()
>>>t + s
(1, 2, 3, 2, 1, 1, 'a', 2, 'b')
>>>print(t, s)
(1, 2, 3, 2, 1) (1, 'a', 2, 'b')
>>>t2 = tuple(set(t))
>>>print(t, t2)
(1, 2, 3, 2, 1) (1, 2, 3)
>>>len(t)
5
>>>t > t2
True
>>>t3 = t2*3
>>>print(t2, t3)
(1, 2, 3) (1, 2, 3, 1, 2, 3, 1, 2, 3)
>>>t3[::3]
(1, 1, 1)
>>>t3[::-1]
(3, 2, 1, 3, 2, 1, 3, 2, 1)
>>>t2 in t3
False
>>>2, 3 in t3
(2, True)
>>>p = 1, 2, [1,2]
(1, 2, [1, 2])
>>> p[-1]
[1, 2]quiz
Please paste the following code into " Submission code " page ," Save and submit comments " Check the results after . Be careful , At this point, the code is not in interactive mode , It's file mode .
t = 1, 2, 3, [1, 2, 3]
try:
t[-1].extend([4, 5, 6])
print(t)
except:
print("error")When defining tuples , A list can be its element , In fact, the pointer to the list is its element . therefore , Tuples require that their elements cannot be modified , As long as the list pointer is not modified . therefore , Here we see a kind of " strange " The phenomenon of , Of a tuple element " value " Can be modified , Please understand this phenomenon reasonably .
边栏推荐
- Blog publishing test 3
- 利用kubernetes资源锁完成自己的HA应用
- 【Redis】List类型
- CTFHub-Web-密码口令-弱口令
- Which brokerage is safer and more convenient to open a stock account for big smart phones?
- 【Redis】Set类型
- [从零开始学习FPGA编程-50]:视野篇 - 芯片是如何被制造出来的?芯片制造的十三大步骤。
- 组合数据类型之元组小练习
- [机缘参悟-33]:眼见不一定为实,大多数时候“眼见为虚”
- 如何成为一名高级数字 IC 设计工程师(5-1)理论篇:时钟技术、复位技术
猜你喜欢

Koa 快速入門

Project R & D, what are the free brain mapping tools that are easy to use

SystemVerilog structure (I)
![[redis] list type](/img/c7/adec2aaea50d69a0aed95bfe683b9e.png)
[redis] list type

Differences between web testing and app testing

MySQL的下载和安装

How to become a senior digital IC Design Engineer (4-5) script: file comparison operation implemented by shell script

Koa 快速入门
![[redis] get to know redis for the first time](/img/02/3c6a7f6ea8c563386a4cd458024728.png)
[redis] get to know redis for the first time

项目研发,有哪些好用的免费脑图工具软件
随机推荐
I have summarized some experiences from the whole process of R & D platform splitting
Examen final de troisième année
字符串分段组合
Which is the best billing method for okcc call center
Is there any risk in opening an account for Dongfang fortune stock? Is it safe for Dongfang fortune to open an account
Digital IC design, FPGA design written examination questions, answers and analysis of autumn move (1) 2022 Ziguang zhanrui (Part 1)
[从零开始学习FPGA编程-49]:视野篇 - 芯片是如何被设计出来的?
【Redis】Hash类型
OpenResty 使用介绍
[network communication learning notes] socket IO setup and deployment
哪个证券公司最大最安全 哪家券商服务好
Flex application: realize two rows and five columns of data, self-adaptive
How to become a senior digital IC Design Engineer (3-5) tools: Spyglass Technology
Studies of relative costs for development in different languages
Why is it recommended that you choose the self research company as much as possible
如何成为一名高级数字 IC 设计工程师(4-5)脚本篇:Shell 脚本实现的文件比较操作
B1009 irony
[learn FPGA programming from scratch -49]: Vision - how is the chip designed?
CTFHub-Web-密码口令-弱口令
Cross border information station