python - 在Python中的某个单词后打印

标签 python raw-input

在Python中,我想读取输入,然后只在某个点之后打印。我希望它像这样工作

    humaninput = raw_input("Please enter:")
    breakdown = humaninput.split()
    say = "say"
    if say in breakdown:
        print (all words after say)

除了最后一部分,我什么都有了

最佳答案

这是一个不使用 split 的简洁替代方案。

string = "string blah say foo bar"
say = "say"
after = string[string.index(say) + len(say):] # +1 if you're worried about spaces
print(after)

>> foo bar

如果有多个“say”实例,它将采用第一个。

关于python - 在Python中的某个单词后打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24814063/

相关文章:

python - 列表未输入第一个输入

c++ - 在 Qt 中获取原始鼠标移动

python - POST 请求始终返回 "Disallowed Key Characters"

python - 奇怪的 HTML 代码看起来像这样 b'\xff\xd8\xff\xe0

python - 如何在 Python 中导入子模块? (没有 `exec` )

Python-如何查看 os.walk 文件内容而不每次打印文件路径?

Python 用户输入回放

带有数据文件的 Python C 扩展

python - python编程时出现Elif错误

python - Python 命令行界面中的 Tab 完成 - 如何捕获 Tab 事件