小编Chr*_*ant的帖子

如果在另一个字符之前找到字符串中的字符

我试图找出一种方法来查看字符串中的字符是否在另一个字符串之前得到并输出.说:

v="Hello There"
x=v[0]

if "Hello" in x:
    print("V consists of '"'Hello'"'")
        if "There" in x:
             print("Hello comes before There)

if "There" in x:
    print("V consists of '"'There'"'")
        if "Hello" in x:
             print("There comes before Hello")
Run Code Online (Sandbox Code Playgroud)

我想要得到的是"你好来到那里",虽然它在我输入时似乎不起作用.帮助将不胜感激.

之所以输出会指示Hello在之前出现是因为脚本是从上到下读取的,这只是对这一事实的利用.

如果其中任何一项没有任何意义,请随时在答案部分与我联系.

python string variables if-statement

0
推荐指数
1
解决办法
1861
查看次数

标签 统计

if-statement ×1

python ×1

string ×1

variables ×1