Alp*_*nse 7 python singleton tuples
我知道这是一种方式,通过放置一个逗号:
>>> empty = ()
>>> singleton = 'hello', # <-- note trailing comma
>>> len(empty)
0
>>> len(singleton)
1
>>> singleton
('hello',)
Run Code Online (Sandbox Code Playgroud)
资料来源:http://docs.python.org/tutorial/datastructures.html
是否有更多方法来定义仅有1个项目的元组?
Jos*_*Lee 11
>>> tuple(['hello'])
('hello',)
Run Code Online (Sandbox Code Playgroud)
但是内置语法是有原因的.