请对比列表list的创建
必须创建的同时进行赋值;创建数据时,可以想多任性就多任性
t = ()
t = tuple() # ()
t = tuple(range(10)) # (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
t = tuple("hi, there.")
# ('h', 'i', ',', ' ', 't', 'h', 'e', 'r', 'e', '.')
t = 1, 2, 3
t = 2,
| list | tuple |
|---|---|
| l = [] | t = () |
| l = [1, 2, 3] | t = (1, 2, 3) |
| l = [[1, 2, 3], [4, 5, 6]] | t = ((1, 2, 3), (4, 5, 6)) |
| l = list(range(10)) | t = tuple(range(10)) |
| l = list('hi, there.') | t = tuple('hi, there.') |
| l = [1] | t = (1,) |