一,序列类型
字符串:“abc”
列表: {“1”,“abc”,0}
元组:[“abc”,“efg”]
代码高亮
# 计算星座
a = "鼠牛虎兔龙蛇马羊猴鸡狗猪"
print("牛" in a)
print("猫" not in a)
zodiac_name = (u'摩羯座', u'水瓶座', u'双鱼座', u'白羊座', u'金牛座', u'双子座', u'巨蟹座',
u'狮子座', u'处女座', u'天秤座', u'天蝎座', u'射手座')
zodiac_day = ((1, 20), (2, 19), (3, 21), (4, 21), (5, 21), (6, 22),
(7, 23), (8, 23), (9, 23), (10, 23), (11, 23), (12, 23))
(month, day)=(6,27)
a = len(list(filter(lambda x: x < (month, day), zodiac_day)))
#print(zodiac_name[a%12])
a_list = ["123", "abc"]
a_list.append(0)
a_list.remove("abc")
print(a_list)
# 计算生肖
chinese_zodiac = '猴鸡狗猪鼠牛虎兔龙蛇马羊'
year = int(input("请输入年份:"))
print("生肖是:" + chinese_zodiac[year % 12])
for year in range(2000, 2020):
print("%s 年是生肖 %s" %(year, chinese_zodiac[year % 12]))
代码高亮
# 计算1到10所有偶数相乘
# 列表推导式,字典推导式
alist = [i*i for i in range(1, 11) if(i % 2 == 0)]
print(alist)
zodiac_name = (u'摩羯座', u'水瓶座', u'双鱼座', u'白羊座', u'金牛座', u'双子座', u'巨蟹座',
u'狮子座', u'处女座', u'天秤座', u'天蝎座', u'射手座')
adict = {i: 0 for i in zodiac_name}
print(adict)