鱼C论坛

 找回密码
 立即注册
查看: 2396|回复: 2

[已解决]“find”和“index”的比较问题

[复制链接]
发表于 2016-11-17 16:58:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

测试如下:
>>> b
'sjkjkjkjk.snknk'
>>> b.find("j")
1
>>> b.index("j")
1
>>> a=list(b)
>>> a
['s', 'j', 'k', 'j', 'k', 'j', 'k', 'j', 'k', '.', 's', 'n', 'k', 'n', 'k']
>>> a.index("k")
2
>>> a.find("k")
Traceback (most recent call last):
  File "<pyshell#42>", line 1, in <module>
    a.find("k")
AttributeError: 'list' object has no attribute 'find'
>>>


请问:在list里面是不是不可以用find函数去查询一个字符?
但好像用index函数是可以的
最佳答案
2016-11-17 17:23:38
  1. >>> dir(list)
  2. ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
  3. >>>
复制代码

list的方法中没有find函数,有index函数
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-11-17 17:23:38 | 显示全部楼层    本楼为最佳答案   
  1. >>> dir(list)
  2. ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
  3. >>>
复制代码

list的方法中没有find函数,有index函数
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-11-17 17:56:57 From FishC Mobile | 显示全部楼层
谢谢大妹子
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-24 00:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表