码迷,mamicode.com
首页 > 编程语言 > 详细

python3元组方法统计

时间:2017-06-24 00:25:36      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:elf   结果   turn   not   方法   --   error   tar   tor   

1、count()

  • 官方说明:
技术分享
    def count(self, value): # real signature unknown; restored from __doc__
        """ T.count(value) -> integer -- return number of occurrences of value """
        return 0
View Code

描述:查找指定元素的索引位置

参数:value  指定的元素

返回值:返回指定元素的索引位置,若没元组中没有这个元素则返回0

  • 示例:
t = (‘william‘,‘lisa‘,‘knight‘,‘pudding‘)
t2 = t.count(‘lisa‘)
print(type(t2),t2)
t3 = t.count(‘xxxxx‘)
print(type(t3),t3)

  输出结果:

技术分享
<class int> 1
<class int> 0
View Code

 

2、index()

  • 官方描述:
技术分享
    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
View Code

描述:和count()一样,查找指定元素的索引位置,不同点是如果元组里没有这个元素则会抛异常

参数:value  指定的元素

返回值:返回指定元素的索引位置,若没元组中没有这个元素则抛异常

示例:

t = (‘william‘,‘lisa‘,‘knight‘,‘pudding‘)
t2 = t.index(‘lisa‘)
print(type(t2),t2)

  输出结果:

技术分享
<class int> 1
View Code

 

python3元组方法统计

标签:elf   结果   turn   not   方法   --   error   tar   tor   

原文地址:http://www.cnblogs.com/fyknight/p/7072040.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!