#通用序列操作
print("#通用序列操作")
numbers = [1,2,3,4,5,6,7,8,9]
print("numbers:",numbers,"\n")
#‘'''索引'''
print("索引:numbers[5] = ",numbers[5],"\n")
#'''切片'''
print("切片:numbers[1:5] = ",numbers[1:5],"\n")
print("切片:numbers[-3:1] = ",numbers[-3:1],"\n")
print("切片:numbers[-3:-1] = ",numbers[-3:-1],"\n")
print("带步长的切片:numbers[0:6:2] = ",numbers[0:6:2],"\n")
print("序列相加:numbers + numbers = ",numbers+numbers,"\n")
print("序列乘法:numbers * 3 = ",numbers*3,"\n")
print("序列成员资格:检查元素是否在序列中,返回bool值 ,例如:1 in numbers = ",1 in numbers,"\n")
print("示例:\n")
database = [
['A','123'],
['B','4567'],
['C','12zsd1']
]
username = input('User Name:')
pin = input('Pin:')
if [username,pin] in database:
print('Access granted')
else:
print('Access Denied')
#通用序列操作
numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9]
索引:numbers[5] = 6
切片:numbers[1:5] = [2, 3, 4, 5]
切片:numbers[-3:1] = []
切片:numbers[-3:-1] = [7, 8]
带步长的切片:numbers[0:6:2] = [1, 3, 5]
序列相加:numbers + numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]
序列乘法:numbers * 3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]
序列成员资格:检查元素是否在序列中,返回bool值 ,例如:1 in numbers = True
示例:
User Name:1
Pin:2
Access Denied