Easy and delays --list python tuple

  • Access list can be back to front, the index -1 is the last element, -2 represents the second countdown, and so on pushing.

  • and tuple list is very similar, but can not modify tuple Once initialized (both sorted containers, can be indexed by the subscript) as immutable tuple, so the code safer. If possible, use a tuple instead of a list as much as possible tuple.

  • [] is a list, tuple is ()

  • We must add a comma when only the definition of a tuple elements to eliminate ambiguity. tu = (1,). Since t = (1), the compiler will be mistaken for the number 1.

  • tuple never be changed it? A small trick.
    = the p-[, 2, 3]
    TU = (1, 2, the p-)
    the p-= [2,3,4]
    thus changing the contents of tuples, then this is not a violation of the rules? Not violated. Because tuples tu third tuple points to the memory address of the list p and p address has not changed, for the tuple, its third element does not change, because it can only see this layer.

Published 73 original articles · won praise 25 · views 3187

Guess you like

Origin blog.csdn.net/qq_37724465/article/details/104758711