一、序列的加法和相乘操作:
序列相加操作:'hello'+'world'
序列相乘操作:s*5
相关运用:
#相加操作
s='hello'
s2='world'
print(s+s2)
#相乘操作
print((s+s2)*5)
print('-'*40)
二、 其他相关操作:
其他相关操作包括:内置函数和序列对象的方法。
操作符/函数符 | 描述说明 |
x in s | x为s的元素,结果为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'))