未打印python子字符串

标签 python find substring

我不知道这部分代码有什么问题

if value.find("\\") > -1:
    newstr = int(value.find("\\"))
    print newstr
    print value
    print value[newstr:7]

newstrvalue 都被正确打印,但是 value[newstr:7] 显示空白。

有什么想法吗?

最佳答案

value[newstr:7] 会给你从位置 newstr 到位置 7

也许你的意思是 value[newstr:newstr + 7]

关于未打印python子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11722854/

相关文章:

javascript - 从头开始从 _underscore.js 编码查找

python高效的子串搜索

python - Sqlalchemy - 根据另一列中的更改更新列

python - "dictionary update sequence element #0 has length 4; 2 is required"

python - 从 Pandas 中的 GroupBy 对象中获取所有键

python - 运行 SimpleHTTPServer 时设置当前目录

jquery查找和替换文本,没有元素id

linux - 删除日期字符串早于 X 天的 yyyy-MM-dd 文件夹

python通过给定开始和结束位置的两个列表连接子字符串

c# - 我怎样才能在C#中获取字符串的前十个字符