Day 02 2018-03-12

Function

def f(x):

no return will return None

Tuples元组

  • an ordered sequence of elements, can mix element types
  • immutable
    t = (2, "mit", 3)
    t[1] = 4 error

conveniently used to swap variable values: (x, y) = (y, x)

def f(x, y)
  a = x // y      //integer division
  b = x % y
return (a , b)

List

  • lists are mutable
    L = [2, 'a', 4, [1,2]]
    len(L)=4
total = 0
for i in L:
  total +=i
print total

add elements: L.append(element)
convert string to list: list(s)
s.split('<')
''.join(L) to turn a list of characters into a string

  • sort() and sorted()
    sorted does not mutate
    sort mutate, return nothing

colone a list: chill = cool[:]

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de F...
    苏黎九歌阅读 13,950评论 0 38
  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 2,060评论 0 2
  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 12,788评论 0 33
  • 几乎在孩子抱走的同时,我开始发抖,麻醉师说是麻药的副作用。剧烈的抖动完全不受控制,只觉得上下牙齿都在不停的摩...
    悦己_蕾蕾阅读 461评论 0 1
  • 如何做人、做事、做官,是不少人需要经常面对和正确把握的大问题,处理好了,则健康成长,反之则裹足不前,甚至掉入人生的...
    氵演员阅读 251评论 0 0