python元组

元组由一系列变量组成的不可变序列
不可变是指一旦创建,不可以添加/删除/修改元素

列表扩容原理
列表有预留空间
预留空间不足时,会在创建新列表(开一块更大的空间)
将原有数据拷贝到新列表中
替换引用

创建空元组

"""
元组
基础操作
不可修改不能增加删除
"""
# 创建空元组
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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值