Python学习心得序列的相关操作

一、序列的加法和相乘操作:

序列相加操作:'hello'+'world'

序列相乘操作:s*5

相关运用:

#相加操作
s='hello'
s2='world'
print(s+s2)

#相乘操作
print((s+s2)*5)
print('-'*40)

二、 其他相关操作:

其他相关操作包括:内置函数和序列对象的方法。

操作符/函数符

描述说明

 x in s

 xs的元素,结果为Ture,否则为False

  x not in s

 x不是s的元素,结果为Ture否则False

 len(s)

序列s中元素的个数(即序列的长度)

 min(s)

序列s中元素的最大值

 max(s)

序列s中元素的最小值

 s.index(x)

序列s中第一次出现元素x的位置

 s.count(x)

序列s中出现x的总次数

 内置函数和序列对象的方法的运用:

#in的使用
s='helloworld'
print('e在helloworld中存在吗?',('e'in s))
print('v在helloworld中存在吗?',('v'in s))

#not in的使用
print('e在helloworld中不存在吗?',('e'not in s))
print('v在helloworld中不存在吗?',('v'not in s))

#内置函数的使用
print('len():',len(s))
print('max():',max(s))
print('min():',min(s))#比较的是ascll码值

#序列对像的方法,使用序列的名称,打点调用
print('s.index():',s.index('o'))
print('s.count():',s.count('o'))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值