- #"""
- 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) /,
来源: http://www.bubuko.com/infodetail-1962974.html