python tuple 方法
2016-01-22 14:46
661 查看
元组:
元组的可使用方法没有list 和str这么多:
1: tuple ---: 类方法,转换为元组类型
class
tuple(object):
"""
tuple() -> empty tuple
tuple(iterable) -> tupleinitialized from iterable's items
If the argument is a tuple, thereturn value is the same object.
"""
2:count ----: 次数;记录值出现的次数
使用方法:
3: index ----: 索引 ; 返回值出现第一次的位置(可选参数start:起始位置,stop;结束位置):测试时出现了问题
使用方法:
元组的可使用方法没有list 和str这么多:
1: tuple ---: 类方法,转换为元组类型
class
tuple(object):
"""
tuple() -> empty tuple
tuple(iterable) -> tupleinitialized from iterable's items
If the argument is a tuple, thereturn value is the same object.
"""
2:count ----: 次数;记录值出现的次数
def count(self, value): # real signature unknown; restored from __doc__ """ T.count(value) -> integer -- return number of occurrences of value """ return 0
使用方法:
t = (11,22,33,44,55,22,44,22) print(type(t)) print(t.count(22)) ### 输出结果 <class 'tuple'> 3
3: index ----: 索引 ; 返回值出现第一次的位置(可选参数start:起始位置,stop;结束位置):测试时出现了问题
def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__ """ T.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present. """ return 0
使用方法:
t = (11,22,33,44,55,22,44,22) #t1 = ('this','is','test') print(t.index(22)) #print(t1.index(is,10,20)) ### 输出结果 1
相关文章推荐
- Python爬虫抓取手机APP的传输数据
- Python面向对象编程指南
- Python判断语句中‘is’和‘==’的区别
- python list方法
- 【MySQL.Connector】Python下读取数据库信息
- python_元组
- python学习中遇到问题
- python实现的直接插入排序算法
- Python 高级特性之列表生成式
- 学习Faster-RCNN (一)跑Faster-RCNN的python版demo
- Python基础复习
- 快速使用Python2.7和Django1.9
- Python下科学计算包numpy和SciPy的安装【原创】
- python IO编程
- python学习笔记
- 【LEETCODE】33-Search in Rotated Sorted Array [Python]
- python 获取当前日期 星期
- 用Python和OpenCV创建一个图片搜索引擎的完整指南 The complete guide to building an image search engine with Python and
- 用Python和OpenCV创建一个图片搜索引擎的完整指南
- 安装python包