首页 > 代码库 > Python基础类型的基础函数总结
Python基础类型的基础函数总结
#""" 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) /,
Python基础类型的基础函数总结
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。