元组由一系列变量组成的不可变序列
不可变是指一旦创建,不可以添加/删除/修改元素
列表扩容原理
列表有预留空间
预留空间不足时,会在创建新列表(开一块更大的空间)
将原有数据拷贝到新列表中
替换引用
创建空元组
"""
元组
基础操作
不可修改不能增加删除
"""
# 创建空元组
tuple01 = ()
# 具有默认值
tuple01 = (1, 2, 3)
# list->tuple
tuple01 = (["a", "b"])
# tuple->list
list01 = list(tuple01)
# 如果元组只有一个元素
tuple02=(100,200)
print(tuple02)
# 获取元素
tuple03=("a","b","c","d")
print(tuple03[0])
a,b=tuple02
# 倒叙打印
for item in range(len(tuple03)-1,-1,-1):
print(item)
"""
输入月份获取天数
"""
month = int(input("请输入一个月份:"))
if month < 1 or month > 12:
print("输入有误")
elif month == 2:
print("28天")
elif month in (4,6,9,11):
print(30)
else:
print(31)
tuple04 = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
moth = int(input("输入月份:"))
if moth < 1 or moth > 12:
print("有误")
else:
print("%d天" % tuple04[moth - 1])
# 3月5日 一月天数+2月天数+5
days_num = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
moth = int(input("请输入月份:"))
days = int(input("请输入天数:"))
# all_days = 0
#
# if moth < 1 or moth > 12:
# print("有误")
# elif moth == 1:
# print("这是第%d天数" % days)
# else:
#
# for item in range(moth - 1):
# all_days += days_num[item]
# all_days += days
# print("这是第%d天数" % all_days)
total = sum(days_num[:moth-1])
total+=days
print("这是第%d天数" % total)