Python 元组只有一个元素

Python中,定义一个元组只有一个元素的时候,写成 tuple=(1,)其中的逗号不可少。

print((1,))


-----结果-----

(1,)


print((1))


-----结果-----

1

如果写成(1)这样的话,python解释为数据1,而非元组。

猜你喜欢

转载自blog.csdn.net/weixin_41514525/article/details/87081628