技巧 #1編碼
字符串翻轉翻譯
>>> a = "codementor">>> print "Reverse is",a[::-1]翻轉後的結果爲 rotnemedoc
技巧 #2code
矩陣轉置blog
>>> mat = [[1, 2, 3], [4, 5, 6]]>>> zip(*mat)[(1, 4), (2, 5), (3, 6)]
技巧 #3ip
a = [1,2,3]字符串
將列表中的三個元素分拆成三個變量變量
>>> a = [1, 2, 3]>>> x, y, z = a>>> x1>>> y2>>> z3
技巧 #4List
a = ["Code", "mentor", "Python", "Developer"]技巧
將字符串列表拼接成一個字符串im
>>> print " ".join(a)Code mentor Python Developer
技巧 #5
List 1 = ['a', 'b', 'c', 'd']
List 2 = ['p', 'q', 'r', 's']
編寫 Python 代碼,實現下面的輸出
>>> for x, y in zip(list1,list2):... print x, y...a pb qc rd s
技巧 #6
僅用一行代碼實現兩個變量的交換