元组的创建方式
"""第一种创建方式,使用()"""
d=('python','world',98)
print(d)
print(type(d)) #使用type查看元素的数据类型
"""第二种创建方式 使用内置函数tuple()"""
a=tuple(('pyhton','world',98))
print(a)
print(type(a))
"""第三种创建方式 只有一个元素 要使用逗号和小括号"""
c=('python',) #如果()里面只有一个元素末尾必须加上逗号 不然系统会默认为str类型 而不是元组
print(c)
print(type(c))
输出结果:
('python', 'world', 98)
<class 'tuple'>
('pyhton', 'world', 98)
<class 'tuple'>
('python',)
<class 'tuple'>
"""空列表的创建方式"""
lst=[]
print(lst)# []
lst2=list()
print(lst2) # []
"""空字典的创建方式"""
lst={}
print(lst)
lst2=dict()
print(lst2)
"""空元组的创建方式"""
t4=()
print(t4)
t5=tuple()
print(t5)
输出结果:
[]
[]
{}
{}
()
()