6、Python-元组
定义
# Python的元组与列表类似,不同之处在于元组的元素不能修改。元组使用小括号,列表使用方括号。
aTuple = ('et',77,99.9)
print(aTuple)
元组的操作
aTuple = ('et',77,99.9)
# 访问元组
print(aTuple[0])
# et
# 修改元组
aTuple[0] = 11
# 'tuple' object does not support item assignment
a = ('a', 'b', 'c', 'a', 'b')
# 左闭右开区间 (b,c),找不到会报错
a.index('a', 1, 3)
print(a.index('a', 1, 4))
#
print(a.count('b'))
#
运算符
+
# 字符串
print("hello " + "xxx")
# hello xxx # 列表
print([1, 2] + [3, 4])
# [1, 2, 3, 4] # 元组
print(('a', 'b') + ('c', 'd'))
# ('a', 'b', 'c', 'd')
*
# 字符串
print('ab' * 4)
# 'ababab' # 列表
print([1, 2] * 4)
# [1, 2, 1, 2, 1, 2, 1, 2] # 元组
print(('a', 'b') * 4)
# ('a', 'b', 'a', 'b', 'a', 'b', 'a', 'b')
in & not in
# 字符串
print('itc' in 'hello itcast')
# True # 列表
print(3 in [1, 2])
# False # 元组
print(4 in (1, 2, 3, 4))
# True # 字典
print("name" in {"name": "Delron", "age": 24})
# True
6、Python-元组的更多相关文章
- Python元组
Python的元组与列表类似,不同之处在于元组的元素不能修改. 元组使用小括号,列表使用方括号. 元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可. 如下实例: tup1 = ('physi ...
- Python 元组内置函数
Python元组包含了以下内置函数 序号 方法及描述 1 cmp(tuple1, tuple2)比较两个元组元素. 2 len(tuple)计算元组元素个数. 3 max(tuple)返回元组中元素最 ...
- Python元组与字典详解
Python 元组 Python的元组与列表类似,不同之处在于元组的元素不能修改. 元组使用小括号,列表使用方括号. 元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可. 如下实例: tup ...
- Python 元组 count() 方法
描述 Python 元组 count() 方法用于统计某个元素在元祖中出现的次数. 语法 count() 方法语法: T.count(obj) 参数 obj -- 元祖中统计的对象. 返回值 返回元素 ...
- Python 元组 index() 方法
描述 Python 元组 index() 方法用于从元祖中找出某个对象第一个匹配项的索引位置,如果这个对象不在元祖中会报一个异常. 语法 index() 方法语法: T.index(obj[,star ...
- Python 元组 tuple() 方法
描述 Python 元组 tuple() 方法用于将可迭代对象(字符串.列表.元祖.字典)转换为元组. 语法 tuple() 方法语法: tuple(iterable) 参数 iterable -- ...
- Python 元组 min() 方法
描述 Python 元组 min() 方法返回元组中元素最小值. 语法 min() 方法语法: min(T) 参数 T -- 指定的元组. 返回值 返回元组中元素最小值. 实例 以下实例展示了 min ...
- Python 元组 max() 方法
描述 Python 元组 max() 方法返回元组中元素最大值. 语法 max() 方法语法: max(T) 参数 T -- 指定的元组. 返回值 返回元组中元素最大值. 实例 以下实例展示了 max ...
- Python 学习笔记(九)Python元组和字典(一)
Python 元组 元组的定义 元组(tuple)是一种Python对象类型,元组也是一种序列 Python中的元组与列表类似,不同之处元组的元素不能修改 元组使用小括号,列表使用方括号 元组的创建 ...
- python 元组拾遗
python 元组拾遗 python 语法糖 def printall(*args): return args 一个以 * 开头的参数将参数聚集为一个元组. printall函数可以接收任意个数的 ...
随机推荐
- POI (Apache POI)
Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. 基本功能 编辑 结构: HSSF - 提供读写Mi ...
- Comparison of Static Code Analysis Tools for Java
http://www.sw-engineering-candies.com/blog-1/comparison-of-findbugs-pmd-and-checkstyle https://stack ...
- Maven 3.3全局配置
Maven采用全局配置的方案: <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to ...
- java基础知识点罗列
1:Java泛型 2:clone Java中的深拷贝(深复制)和浅拷贝(浅复制) Java中对Clone的理解 序列化和反序列化的概念 3:Java中有关Null的9件事
- 日常工作: 应用服务器Oracle驱动问题说明
1. .net使用Oracle驱动的发展等 作为.net线的产品的ERP产品 最初的版本 使用了.net 1.1发布时 微软提供的Oracle的驱动 但是后续微软的.net产品线貌似没有继续发展相应的 ...
- 软件工程_1st weeks
本周为软件工程课的第一周,本周主要完成了三个工作:了解了github并使用.拜读了<构建之法>并开通了博客以及完成了四则运算的代码实现. 对于第一项工作github的安装和使用,花费了5个 ...
- scipy插值interpolation
>>> from scipy.interpolate import interp1d#interp1d表示1维插值 >>> >>> x = np. ...
- MidoNet 安装(Kilo RDO)(最老版)
一.初始化(Kilo RDO)版(最老版) 环境介绍 系统 CentOS 7.3 主机ip 10.211.55.5 主机名 midonet 1.配置yum源 ###OpenStack源 yum ins ...
- StringBuilder String string.Concat 字符串拼接速度再议
首先看测试代码: public class StringSpeedTest { "; public string StringAdd(int count) { string str = st ...
- __add__运行过程