%:求余
閏年標(biāo)準(zhǔn)(并且條件注意是大于2月)
# 判斷閏年
if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
if month > 2:
days += 1
print('這是第{}天。'.format(days))
集合操作:
s-t 或s.difference(t) —— 返回在集合s中但不再t中的元素
s&t 或s.intersection(t) —— 取交集
s | t 或s.union(t) —— 取并集
s^t 或s.symmetric_difference(t) —— 返回不包括交集的s和t中的元素
字典
字典類型(dict)是“鍵-值”數(shù)據(jù)項(xiàng)的組合,每個元素是一個鍵值對
如:身份證號(鍵)--個人信息(值)
字典類型數(shù)據(jù)通過映射查找數(shù)據(jù)項(xiàng)
映射:通過任意鍵查找集合中的值的過程
字典類型以鍵為索引,一個鍵對應(yīng)一個值
字典類型的數(shù)據(jù)是無序的
d['egg'] = 2.59
d
{‘egg’:2.59}
d['milk'] = 3.19
d
{'egg':2.59,‘milk’:3.19}
del d['milk']
d
{'milk':3.19}