官术网_书友最值得收藏!

Tuples

The final built-in data type is the tuple. Python tuples work exactly like Python lists except they are immutable; that is, they can't be changed in place. They are normally written inside parentheses to distinguish them from lists (which use square brackets), but as you'll see, parentheses aren't always necessary; however, a comma is always required, as expressions can use parentheses too. Since tuples are immutable, their length is fixed. To grow or shrink a tuple, a new tuple must be created.

Since parentheses can surround expressions, you have to show Python when a single item is actually a tuple by placing a comma after the item. A tuple without parentheses can be used when a tuple is unambiguous. However, it's easier to just use parentheses than to screenshot out when they're optional.

主站蜘蛛池模板: 栾城县| 绵阳市| 浏阳市| 濮阳县| 刚察县| 乌拉特中旗| 延庆县| 清流县| 东阿县| 会同县| 姚安县| 安多县| 资阳市| 三原县| 丁青县| 吴川市| 盐津县| 双辽市| 运城市| 专栏| 台湾省| 子长县| 韶关市| 武夷山市| 塔河县| 萨嘎县| 昆山市| 绥中县| 安化县| 阜宁县| 临桂县| 北宁市| 法库县| 红河县| 翼城县| 永宁县| 铁力市| 安宁市| 木兰县| 阳朔县| 景宁|