索引:
#将输入的数按指定年、月、日的日期打印出来 months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', ] endings = ['st','nd','rd']+17*['th']\ +['st','nd','rd']+7*['th']\ +['st'] year = input('Year:') month = input('Month(1-12):') day = input('Day(1-31):') month_number = int(month) day_number = int(day) month_name = months[month_number-1] ordinal = day+endings[day_number-1] print(month_name + ' '+ordinal+','+ year) url = input('Please enter the URL:') domain = url[11:-4:1] print("Domain name:"+domain) #序列相加,不能拼接不同类型的序列 [1,2,3]+[4,5,6] 'hello,'+'world!' #乘法 'python'* 5 #空列表 sequence = [None]*10 #成员资格,判断特定的值是否包含在序列中,使用运算符in permissins = 'rw' 'w' in permissions #检查用户名和PIN码 databsse = [ ['albert','1234'], ['dilbert','4242'], ['smith','7524'], ['jones','9843'] ] username = input('User name:') pin = input('PIN code:') if[username,pin] in database:print('Access granted') #长度、最小值、最大值 number = [100,23,478] len(number) max(number) min(number) #深拷贝和浅拷贝 a=[1,2,3] b=a b[1] = 4 a #输出结果[1,4,3] a=[1,2,3] b = a.copy() b[1]=4 a #输出结果[1,2,3]