|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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函数是可以的
- >>> dir(list)
- ['__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']
- >>>
复制代码
list的方法中没有find函数,有index函数
|
|