Is this 'file' entity a tuple?
本问题已经有最佳答案,请猛点这里访问。
1  | file = ('cropdata.txt')  | 
我不太确定元组是什么。这是一个元组吗?元组与列表或字符串有何不同?
不,
1 2 3  | this_is_a_tuple = ('cropdata.txt',)  # Parenthesis are used for Order-of-operations grouping this_is_a_string = ('cropdata.txt') # Notice, no comma. this_is_also_a_tuple = 'cropdata.txt',  | 
但是,使用空括号创建空元组:
1  | this_is_an_empty_tuple = ()  # Look mom, no comma!  | 
至于元组是什么,它只是一个保存对其他对象引用的对象。其他对象可以按索引查找:
1 2 3  | my_tuple = ('foo', 2) my_tuple[0] # foo my_tuple[1] # 2  | 
元组也可以是iterable:
1 2  | for item in my_tuple: ...  | 
如果你熟悉