Python的 解构 与 集合
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 解构与封装 一、解构 In [1]: x = 1 In [2]: y = 2 In [3]: x, y = y, x # Python 的解构 In [4]: print(x, y) 2 1 In [5]: lst = [1, 2] In [6]: first = lst[0] In [7]: second = lst[1] In [8]: first, second = lst In [9]: print(first, second) 1 2 In [10]: 解构:按元素顺序,把线性结构的元素,赋值给变量 二、封装 In [10]: t = 1, 2 In [11]: t Out[11]: (1, 2) In [12]: type(t) Out[12]: tuple In [13]: 封装:定义一个元组,可以忽略小括号,封装出来的一定是元组 In [21]: t = 1, 2 In [22]: t Out[22]: (1, 2) In [23]: t1 = 1, 2 In [24]: t2 = (1, 2) In [25]: t1 == t2 Out[25]: True In [26]: t1 is t2 Out[26]: False 三、Python3 中的解构变化 In [1]: lst = list