Python Tuple元组的操作说明
Tuple的特性在于,它的元素是不可变的(immutable),一旦设定,就不能使用索引去修改。
>>> t1=1,2,3,4,5 #给Tuple赋值
>>> t1[0] #按照索引读取Tuple元素
1
>>> u1=t1,(2,3,4,5,6)#tuple可以嵌套
>>> u1
((1, 2, 3, 4, 5), (2, 3, 4, 5, 6))
>>> u1[1]
(2, 3, 4, 5, 6)
>>> u1[-1]
(2, 3, 4, 5, 6)
>>> u1=t1,(2,3,4,5,6),3
>>> u1
((1, 2, 3, 4, 5), (2, 3, 4, 5, 6), 3)
>>> list1=['we','the','north']
>>> list1
['we', 'the', 'north']
>>> u1=t1,list1
>>> u1
((1, 2, 3, 4, 5), ['we', 'the', 'north'])
>>> list1[-1]='toronto'#元组内的元素是可变的,所以可以修改内部元素来更新元组
>>> u1
((1, 2, 3, 4, 5), ['we', 'the', 'toronto'])
>>> len(u1)
2
>>> myList = [1,2,3,4,5,6,7,8,9,10]
>>> myTuple = (1,2,3,4,5,6,7,8,9,10)
>>> myList=(2,)#初始化一个元素的时候,需要带comma
>>> myList
(2,)
>>> myList[0]
2
>>> myList[1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
>>> len(myList)
1
Python Tuple元组的操作说明的更多相关文章
- Python tuple 元组
Python 元组 Python的元组与列表类似,不同之处在于元组的元素不能修改. 元组使用小括号,列表使用方括号. 元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可. 如下实例: tup1 ...
- Python Tuple(元组) tuple()方法
描述 Python 元组 tuple() 函数将列表转换为元组.每组词 www.cgewang.com 语法 tuple()方法语法: tuple( iterable ) 参数 iterable -- ...
- Python Tuple(元组) min()方法
描述 Python 元组 min() 函数返回元组中元素最小值.高佣联盟 www.cgewang.com 语法 min()方法语法: min(tuple) 参数 tuple -- 指定的元组. 返回值 ...
- Python Tuple(元组) max()方法
描述 Python 元组 max() 函数返回元组中元素最大值.高佣联盟 www.cgewang.com 语法 max()方法语法: max(tuple) 参数 tuple -- 指定的元组. 返回值 ...
- Python Tuple(元组) len()方法
描述 Python 元组 len() 函数计算元组元素个数.高佣联盟 www.cgewang.com 语法 len()方法语法: len(tuple) 参数 tuple -- 要计算的元组. 返回值 ...
- python——tuple元组
>>> dir(tuple) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', ...
- Python tuple元组学习
1.tuple和list非常类似,但是tuple一旦初始化就不能修改 classmates = ('Michael', 'Bob', 'Tracy') 现在,classmates这个tuple不能变了 ...
- Python Tuple(元组) cmp()方法
描述 Python 元组 cmp() 函数用于比较两个元组元素.高佣联盟 www.cgewang.com 语法 cmp()方法语法: cmp(tuple1, tuple2) 参数 tuple1 -- ...
- Python数据类型的内置函数之tuple(元组),dict(字典),set(集合)
Python数据类型内置函数 - str(字符串) - list(列表) - tuple(元组) - dict(字典) - set(收集) tuple(元组)的操作 - (count)统计元组中元素出 ...
随机推荐
- 深入了解JAVA基础(面试)
I.常用类型与编码类问题: 1.Java中的基本类型有什么? byte.short.int.long.float.double.chart.boolean这八种,这 ...
- Python笔记(五)_内置函数BIF
查看所有的内置函数:dir(__builtins__) abs() 获取绝对值 max() 返回给定元素中的最大值 min() 返回给定元素中的最小值 sum() 求和 reverse ...
- git使用记录三:查看日志
git使用记录三: git log git log 的帮助文档 git log --help 查看最后面的两个日志记录 命令如下: git log -n number 比如: git log -n 2 ...
- js中的经典案例--简易万年历
js中的经典案例--简易万年历 html代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...
- UVA1608_Non-boring sequences
Non-boring sequences 大致题意: 给你一个字符串,问你他的任一子串是否都包含一个唯一的字符 思路: 看似简单,实际一丁点思路都没有 后面看汝佳的讲解都看了好长时间 大概思路就是,先 ...
- 阮一峰 ES6
阮一峰 ES6:http://es6.ruanyifeng.com/#docs/module
- SpringBoot集成Swagger,Postman,newman,jenkins自动化测试.
环境:Spring Boot,Swagger,gradle,Postman,newman,jenkins SpringBoot环境搭建. Swagger简介 Swagger 是一款RESTFUL接口的 ...
- Guava 开源工具的简单介绍
Guava 是一个 Google 的基于java1.6的类库集合的扩展项目,包括 collections, caching, primitives support, concurrency libra ...
- Node中的Cookie和Session
1.Cookie HTTP是无状态协议.例:打开一个域名的首页,进而打开该域名的其他页面,服务器无法识别访问者.即同一浏览器访问同一网站,每次访问都没有任何关系. Cookie的原理是:客户端浏览器在 ...
- 创建Uboot 环境变量 bin 文件
As we know, the bootloader stores its configuration into an area of the flash called the environment ...