【发布时间】:2016-10-18 18:42:00
【问题描述】:
我正在尝试找出一种方法来查看字符串中的一个字符是否在另一个字符之前获取和输出。说:
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")
我想要得到的是“Hello come before there”,尽管当我输入它时它似乎不起作用。非常感谢帮助。
输出会显示Hello出现在there之前的原因是因为脚本是从上到下读取的,这只是对这一事实的利用。
如果其中任何一个没有任何意义,请随时在答案部分与我联系。
【问题讨论】:
标签: python string variables if-statement