《Beginning Python From Novice to Professional》学习笔记四:Tuple
来源:互联网 发布:js获取input file值 编辑:程序博客网 时间:2024/04/27 07:48
Tuple与List最大的区别就是Tuple的元素不可更改(和String一样),其它几乎感觉不到区别(The only difference is that tuples can’t be changed.)
1.元素后出现逗号就自动成为Tuple
1,2,3 ---> (1,2,3)
(1,2,3) ---> (1,2,3)
18, ---> (18,) #仅有一个元素
注意以下两例的区别:
3*(40+2) ---> 126
3*(40+2,) ---> (42, 42, 42)
2.Tuple转换
tuple([1, 2, 3]) ---> (1, 2, 3)
tuple('abc') ---> ('a', 'b', 'c')
tuple((1, 2, 3)) ---> (1, 2, 3)
小结,使用Tuple的两种可能:作为mapping的keys;以及作为内置函数的返回值。In general, lists will probably be adequate for all your sequencing needs.
1.元素后出现逗号就自动成为Tuple
1,2,3 ---> (1,2,3)
(1,2,3) ---> (1,2,3)
18, ---> (18,) #仅有一个元素
注意以下两例的区别:
3*(40+2) ---> 126
3*(40+2,) ---> (42, 42, 42)
2.Tuple转换
tuple([1, 2, 3]) ---> (1, 2, 3)
tuple('abc') ---> ('a', 'b', 'c')
tuple((1, 2, 3)) ---> (1, 2, 3)
小结,使用Tuple的两种可能:作为mapping的keys;以及作为内置函数的返回值。In general, lists will probably be adequate for all your sequencing needs.
- 《Beginning Python From Novice to Professional》学习笔记四:Tuple
- 《Beginning Python From Novice to Professional》学习笔记一:String
- 《Beginning Python From Novice to Professional》学习笔记二:Sequence
- 《Beginning Python From Novice to Professional》学习笔记三:List
- 《Beginning Python From Novice to Professional》学习笔记六:Dictionary
- 《Beginning Python From Novice to Professional》学习笔记七:Statement
- 《Beginning Python From Novice to Professional》学习笔记八:Abstraction
- 《Beginning Python From Novice to Professional》学习笔记十:Exception
- 《Beginning Python From Novice to Professional》学习笔记十一:__Magic__
- 《Beginning Python From Novice to Professional》学习笔记十二:__Magic__
- Beginning Python: From Novice to Professional
- 《Beginning Python From Novice to Professional》学习笔记五:Advanced String
- 《Beginning Python From Novice to Professional》学习笔记九:More Abstraction
- Beginning Python From Novice to Professional (3) - 列表操作
- Beginning Python From Novice to Professional (6) - 函数使用
- Beginning Python From Novice to Professional (7) - 类
- Beginning Python From Novice to Professional (8) - 文件方法
- Beginning Python From Novice to Professional (9) - Socket
- .NET(C#)中实现显示客户端时间
- fjnu2048 研究了好久 还从判 晕!
- #pragma的用法
- 在VC中如何使程序开机时自动运行
- pku3579 操二分查找真烦人 都搞两天了!
- 《Beginning Python From Novice to Professional》学习笔记四:Tuple
- 突然发现我该把实习的经历写出来,等到以后7老8十了....
- 《Beginning Python From Novice to Professional》学习笔记五:Advanced String
- RMI代码动态下载
- 《Beginning Python From Novice to Professional》学习笔记六:Dictionary
- VC雕虫小技集
- 有许多都无法改变!
- 生活琐事
- 移动占先机,TD获得最佳开局