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

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.

主站蜘蛛池模板: 永仁县| 措美县| 临高县| 通道| 大埔区| 荔浦县| 郴州市| 通州市| 尼勒克县| 武定县| 庆元县| 九寨沟县| 浦城县| 宁夏| 河源市| 五大连池市| 五莲县| 迁西县| 沙田区| 肥乡县| 新巴尔虎右旗| 彰化县| 永和县| 开封市| 重庆市| 定西市| 富源县| 清水县| 绥德县| 山东| 化德县| 安吉县| 海丰县| 宜君县| 罗甸县| 广州市| 禹州市| 北川| 西宁市| 黑水县| 来安县|