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

Tuples

Tuples are just like lists, except they're immutable, so you can't actually extend, append, or sort them. They are what they are, and they behave just like lists, apart from the fact that you can't change them, and you indicate that they are immutable and are tuple, as opposed to a list, using parentheses instead of a square bracket. So you can see they work pretty much the same way otherwise:

#Tuples are just immutable lists. Use () instead of []
x = (1, 2, 3)
len(x)

The output of the previous code is as follows:

3

We can say x= (1, 2, 3). I can still use length - len on that to say that there are three elements in that tuple, and even though, if you're not familiar with the term tuple, a tuple can actually contain as many elements as you want. Even though it sounds like it's Latin based on the number three, it doesn't mean you have three things in it. Usually, it only has two things in it. They can have as many as you want, really.

主站蜘蛛池模板: 三门县| 江北区| 莱阳市| 丁青县| 莫力| 青龙| 哈密市| 榆树市| 太康县| 罗山县| 平舆县| 洛川县| 盘锦市| 肇源县| 彭泽县| 灵川县| 烟台市| 泰来县| 运城市| 雷波县| 韶山市| 泰和县| 万源市| 新津县| 祁东县| 台安县| 伊吾县| 荣昌县| 巩义市| 湟源县| 吕梁市| 弋阳县| 那曲县| 巴里| 鹤庆县| 九龙县| 墨江| 同仁县| 双鸭山市| 昌宁县| 宁波市|