美文网首页
Day 02 2018-03-12

Day 02 2018-03-12

作者: 刘洋_2ac6 | 来源:发表于2018-03-13 00:08 被阅读0次

    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[:]

    相关文章

      网友评论

          本文标题:Day 02 2018-03-12

          本文链接:https://www.haomeiwen.com/subject/eptafftx.html