python基础【二】
原创
©著作权归作者所有:来自51CTO博客作者wx633288bd5c53e的原创作品,请联系作者获取转载授权,否则将追究法律责任
序列类型的内建函数
判断成员是否属于序列
aList = ['Mon', 'Tus', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun']
print('Mon' in aList)
aList = ['Mon', 'Tus', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun']
print('Mon'not in aList)
序列类型转换内建函数
str = 'Hello World'
a = list(str)
print(a)
str = 'Hello World'
a = tuple(str)
print(a)
print(type(str(123)))
#<class 'str'>
其他序列类型的内建函数
aList = ['Mon', 'Tus', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun']
len = len(aList)
print('序列的长度是',len)
aList = [1,4,2,5,6,78,0,9]
a = sorted(aList)
print(a)
aList = [1,4,2,5,6,78,0,9]
a = list(reversed(aList))
#值得注意的地方
print(a)
aList = [1,4,2,5,6,78,0,9]
a = sum(aList)
print(a)
aList = [1,4,2,5,6,78,0,9]
a = max(aList)
print(a)
aList = [1,4,2,5,6,78,0,9]
a = min(aList)
print(a)
aList = ['Mon', 'Tus', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun']
a = list(enumerate(aList))
print(a)
a = 'hello'
b = 'world'
c = list(zip(a,b))
print(c)
#[('h', 'w'), ('e', 'o'), ('l', 'r'), ('l', 'l'), ('o', 'd')]
字符串的方法
aStr = 'hello'
print(aStr.center(15))
aStr = 'hello'
print(aStr.count('l'))
aStr = 'hello'
print(aStr.find('lo'))
= 'hello'
print(aStr.replace('h', "H"))
- split方法,默认按空格分开这个字符串,返回一个序列
aStr = 'he llo wo rld'
print(aStr.split())
结果:['he', 'llo', 'wo', 'rld']
aStr = ' hello world '
print(aStr.strip())