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

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.

主站蜘蛛池模板: 无极县| 普宁市| 玉门市| 芦溪县| 曲靖市| 宾阳县| 金湖县| 西城区| 左权县| 太原市| 富蕴县| 闻喜县| 保德县| 建水县| 仪陇县| 辽宁省| 澄江县| 彰武县| 吉林市| 凌源市| 大埔区| 灵山县| 岗巴县| 云和县| 日喀则市| 凯里市| 上高县| 大新县| 桐乡市| 横山县| 馆陶县| 五寨县| 抚远县| 无棣县| 卫辉市| 那曲县| 丰镇市| 尉氏县| 浦东新区| 普洱| 凤城市|