if a in ('a', 'b', 'c',):
# do somethingif a in ['a', 'b', 'c']:
# do something--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
要发帖到此群组,请发送电子邮件至python-cn@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
--
您收到此邮件是因为您订阅了Google网上论坛上“python-cn(华蟒用户组,CPyUG 邮件列表)”群组中的主题。
要退订此主题,请访问https://groups.google.com/d/topic/python-cn/sbB6r3SkTGo/unsubscribe。
要退订此群组及其所有主题,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
您收到此邮件是因为您订阅了Google网上论坛上“python-cn(华蟒用户组,CPyUG 邮件列表)”群组中的主题。
要退订此主题,请访问https://groups.google.com/d/topic/python-cn/sbB6r3SkTGo/unsubscribe。
要退订此群组及其所有主题,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了 Google 网上论坛上“python-cn(华蟒用户组,CPyUG 邮件列表)”群组中的主题。
要退订此主题,请访问https://groups.google.com/d/topic/python-cn/sbB6r3SkTGo/unsubscribe。
要退订此群组及其所有主题,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
要向此群组发帖,请发送电子邮件至 pyth...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/d/optout。
很久以前,tuple iterate的时候速度比其他类型快
http://www.diveintopython3.net/native-datatypes.html#tuples
https://stackoverflow.com/questions/3340539/why-is-tuple-faster-than-list
Sent from Mail for Windows 10
要退订此群组及其所有主题,请发送电子邮件到python-cn+...@googlegroups.com。
要向此群组发帖,请发送电子邮件至 pyth...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/d/optout。
--
Alvin Qi
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+...@googlegroups.com。
要发帖到此群组,请发送电子邮件至pyth...@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
我也发现了,确实是这样。
虽然不是很懂底层区别,但从代码风格上向社区靠拢是没错的。
要退订此群组及其所有主题,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
要向此群组发帖,请发送电子邮件至 pyth...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/d/optout。
--
Alvin Qi
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
要发帖到此群组,请发送电子邮件至python-cn@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
我也发现了,确实是这样。
虽然不是很懂底层区别,但从代码风格上向社区靠拢是没错的。
要退订此群组及其所有主题,请发送电子邮件到python-cn+unsub...@googlegroups.com。
--
Alvin Qi
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
要发帖到此群组,请发送电子邮件至python-cn@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
$ python2.6 -mtimeit '(1, 2, 3, 4)'
10000000 loops, best of 3: 0.0266 usec per loop
$ python2.6 -mtimeit '[1, 2, 3, 4]'
10000000 loops, best of 3: 0.163 usec per loop要退订此群组及其所有主题,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
要向此群组发帖,请发送电子邮件至 pyth...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/d/optout。
--
Alvin Qi
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
要发帖到此群组,请发送电子邮件至python-cn@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
是自动优化了,之前贴的那篇文章有提到
Furthermore, Python does the same thing to lists. If a literal list object is put in a membership test, Python will replace it with an actual tuple constant in the code
您收到此邮件是因为您订阅了Google网上论坛上“python-cn(华蟒用户组,CPyUG 邮件列表)”群组中的主题。
要退订此主题,请访问https://groups.google.com/d/topic/python-cn/sbB6r3SkTGo/unsubscribe。
要退订此群组及其所有主题,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
我觉得tuple当成可遍历的数据结构是误用
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+...@googlegroups.com。
要发帖到此群组,请发送电子邮件至pyth...@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
--彼節者有間,而刀刃者無厚;以無厚入有間,恢恢乎其於游刃必有餘地矣。
blog: http://shell909090.org/
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+...@googlegroups.com。
要发帖到此群组,请发送电子邮件至pyth...@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上“python-cn(华蟒用户组,CPyUG 邮件列表)”群组中的主题。
要退订此主题,请访问https://groups.google.com/d/topic/python-cn/sbB6r3SkTGo/unsubscribe。
要退订此群组及其所有主题,请发送电子邮件到python-cn+...@googlegroups.com。----Alvin Qi
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
The nature of tuples In 2012 I presented a poster about the ABC language at PyCon US. Before creating Python, Guido had worked on the ABC interpreter, so he came to see my poster. Among other things, we talked about the ABC compounds which are clearly the predecessors of Python tuples. Compounds also support parallel assignment and are used as com‐ posite keys in dictionaries (or tables, in ABC parlance). However, compounds are not sequences. They are not iterable and you cannot retrieve a field by index, much less slice them. You either handle the compound as whole or extract the individual fields using parallel assignment, that’s all. I told Guido that these limitations make the main purpose of compounds very clear: they are just records without field names. His response: “Making tuples behave as se‐ quences was a hack.” This illustrates the pragmatic approach that makes Python so much better and more successful than ABC. From a language implementer perspective, making tuples behave as sequences costs little. As a result, tuples may not be as “conceptually pure” as com‐ pounds, but we have many more ways of using them. They can even be used as immut‐ able lists, of all things! It is really useful to have immutable lists in the language, even if their type is not called frozenlist but is really tuple behaving as sequence.
元组的本质
2012年,我在PyCon US上贴了一张关于ABC语言的墙报。Guido在开创Python语 言之前曾做过 ABC 解释器方面的工作,因此他也去看了我的墙报。我们聊了不少,而 且都提到了 ABC 里的 compounds 类型。compounds 算得上是 Python 元组的鼻祖,它既 支持平行赋值,又可以用在字典(dict)里作为合成键(ABC 里对应字典的类型是表 格,即 table)。但 compounds 不属于序列,它不是迭代类型,也不能通过下标来提取 某个值,更不用说切片了。要么把 compounds 对象当作整体来用,要么用平行赋值把 里面所有的字段都提取出来,仅此而已。
我觉得tuple当成可遍历的数据结构是误用
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
要发帖到此群组,请发送电子邮件至python-cn@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
--彼節者有間,而刀刃者無厚;以無厚入有間,恢恢乎其於游刃必有餘地矣。
blog: http://shell909090.org/
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
要发帖到此群组,请发送电子邮件至python-cn@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上“python-cn(华蟒用户组,CPyUG 邮件列表)”群组中的主题。
要退订此主题,请访问https://groups.google.com/d/topic/python-cn/sbB6r3SkTGo/unsubscribe。
要退订此群组及其所有主题,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
----Alvin Qi
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了 Google 网上论坛上“python-cn(华蟒用户组,CPyUG 邮件列表)”群组中的主题。
要退订此主题,请访问https://groups.google.com/d/topic/python-cn/sbB6r3SkTGo/unsubscribe。
要退订此群组及其所有主题,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
我觉得tuple当成可遍历的数据结构是误用
要退订此群组及其所有主题,请发送电子邮件到python-cn+unsub...@googlegroups.com。
list里保存不同类型对象不是给自己埋坑吗?
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了 Google 网上论坛的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+...@googlegroups.com。
不是,比如list的对象是用来遍历的,那么只要list中保存的对象实现了迭代,那么无论对象的类型是list,tuple,dict或者自定义类型都是无所谓的。
这是动态语言一个方便的地方。
从你的回帖来看,你是Java这种静态语言用多了,才会觉得list里面对象不同类型是埋坑。
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+unsubscribe@googlegroups.com。
A tuple is an object that you use very often without even noticing it. When you look at it initially, it seems like a useless data structure. It's like a list that you can't modify, so why not just use a list? There are a few cases where a tuple offers some really useful functionalities that a list does not. Firstly, they are hashaable. This means that you can use a tuple as a key in a dict, which is something a list can't do.
set – like a dict without values