python 元组和方法
来源:互联网 发布:牛股选股器源码 编辑:程序博客网 时间:2024/05/16 18:24
一元组是什么?
tuple 是不可变的List ,区别由[ ] 变为( ),另外,tuple 不能增加和减少。
1. tuple 定义:
str1='abdcccccccc;cccc'print(tuple(str1))print(type(tuple(str1)))
('a', 'b', 'd', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', ';', 'c', 'c', 'c', 'c')<type 'tuple'>创建空元组
b = ();print (type(b))
<type 'tuple'>只包含一个元素时,需要在元素后面添加逗号。
b = (123,);print (b)print (type(b))
(123,)<type 'tuple'>方法:
1.count /统计tuple 中某个元素的个数
t1=('a','b','c','a','d','c')print (t1.count('a'))
22.index 返回某个元素的下标
a=(1,2,3,'a',b'')print (a.index('a'))
3
阅读全文
0 0
- python 元组和方法
- python列表方法和元组
- python列表方法和元组
- python 的序列方法,元组和列表的方法。
- python字符串、元组和列表常用的一些方法
- python列表和元组
- Python列表和元组
- Python 列表和元组
- Python 列表和元组
- Python列表和元组
- python 列表和元组
- python-列表和元组
- python列表和元组
- python列表和元组
- python 列表和元组
- python--列表和元组
- Python列表和元组
- Python 列表和元组
- 输出10个100以内的随机数(c实现)
- c++构造函数
- 递归函数
- 文章标题
- HTTP服务器返回的代码详解
- python 元组和方法
- 四种获取下标的方法
- Linux 下的任务自动化
- 【CodeForces
- redis集群
- php中单引号和双引号的区别
- 常用命令:cd/rm & 创建和删除目录
- .Net Framework
- HDU-2955 01背包