Python 创建一个项目的元组

创建一个项目的元组

要创建一个只包含一个项目的元组,你需要在项目后面添加一个逗号,否则 Python 将不会把变量识别为元组。

实例

一个项目的元组,记住逗号:

thistuple = ("apple",)
print(type(thistuple))

# 不是元组:
thistuple = ("apple")
print(type(thistuple))

亲自试一试