【Python--序列的基本操作】索引/切片/相加/乘法/成员资格判断

#通用序列操作
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值