当你有一个包含的代码时
find list[7].find('~') == -1
process
Run Code Online (Sandbox Code Playgroud)
在这种情况下,-1代表什么?
我试图将数字更改为不同的数字,但不断收到错误.
-1由返回find()时,在字符串中没有找到一个特定的字符串,否则返回字符串的索引.在你的情况下lis[7]是一个字符串,你正在调用find()它.
In [23]: 'abc'.find('d')
Out[23]: -1
In [24]: 'abc'.find('b')
Out[24]: 1
Run Code Online (Sandbox Code Playgroud)
从Python文档:
str.find(sub [,start [,end]]) -> int
Return the lowest index in S where substring sub is found,
such that sub is contained within s[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
Run Code Online (Sandbox Code Playgroud)
PS:不要list用作变量名
| 归档时间: |
|
| 查看次数: |
220 次 |
| 最近记录: |