您的位置:首页 > 编程语言 > Python开发

Python基础类型的基础函数总结

2017-02-27 21:01 190 查看
#"""
sets    """

len+*find,replacesplitisalpha,isdigit,rstrip"%s"str
len(s)s[0],s[-1]
(raw)s = 'sam'
s = 'S'+s[1:]
print s
Sam
line= 'aaa,bbb,ccc,ddd'
print line.split(',')
line = line.split(',')
print line
"result":['aaa', 'bbb', 'ccc', 'ddd']
['aaa', 'bbb', 'ccc', 'ddd']
line= 'aaa,bbb,ccc,ddd,\n'
line = line.rstrip()##print line
aaa,bbb,ccc,ddd,

print '%s is %s' % ('I', 'you')
print '%s' % 'you'
I is you
you

(...)
appendpop,sort,reverse,insert,        remove,rstrip....

list
list"".joinlistlist1 = [1, 3, 4, 5, 5, 7]
print list1[0]
list1[0]=22
print list1
print list1[0:3:1] ##list1[begin:end:step]

base = ['a', 'b', 2.33, ['a', 'bc']]
base.append(('abc',))
print base  ##base.append['a', 'b', 2.33, ['a', 'bc'], ('abc',)]
base = ['a', 'b', 2.33, ['a', 'bc']]
base.append(('abc',))   ##print base
base.pop(2)     ##print base
base.sort()     ##print base
base.reverse()  ##print base
['a', 'b', 2.33, ['a', 'bc'], ('abc',)]
['a', 'b', ['a', 'bc'], ('abc',)]
[['a', 'bc'], 'a', 'b', ('abc',)]
[('abc',), 'b', 'a', ['a', 'bc']]
foriterable()res = [ord(x) for x in 'spam'] ##ord()ASCIIprint res
[115, 112, 97, 109]

[expression for target1 in iterable1 [if condition1]]..
for targetn in iterablen[if condition]
ifdef fun():
return [(x,y) for x in range(5) if x % 2 == 0 for   y in range(5) if y%2 ==1]
print fun()
[(0, 1), (0, 3), (2, 1), (2, 3), (4, 1), (4, 3)]

D[key]Dkeyvalue,D.keys()DKeyKeyvalue,keyclear()keys()values(),items()D.get(key[,d])keyD[key],d,None
pop(key[,d])keykeyssortD = {'a': 1, 'b': 2}
print D
Ks = list(D.keys())
print Ks
Ks.reverse()
print Ks
for key in Ks:
print (key, '==>', D[key])
('b', '==>', 2)
('a', '==>', 1)

tuple
T.index(4)  4T.count(4)  4tup1+tup2del tup,cmp(tup1,tup2)  len(tup)        max/min(tuple)      /,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  list tuple dict