【发布时间】:2017-12-06 02:28:21
【问题描述】:
想知道是否有一种方法可以让 python 在输入语句中接受“save”或“s”,以便在每次将其输入到 .py 文件中的任何 if/elif/else 时执行某些操作,所以我不知道不必重复 if/elif/else 几次。我想要这样的东西
a=input("some other question that i want to accept s/save: ")
b=input("Again but i dont want 2 if statments: ")
而不是。
a=input("question: ")
if a == "y":
print("something")
elif a == "y":
print("Something")
elif a in ("s", "save")
print("save")
else:
print("not option")
print("A bunch of other code for 100 lines")
a=input("question: ")
if a == "y":
print("something")
elif a == "y":
print("Something")
elif a in ("s", "save")
print("save")
else:
print("not option")
等通过代码
【问题讨论】:
-
试试
dictionary。 -
功能不就是为了这个吗?
def ask_question(): ... -
?我不明白
标签: python python-3.x if-statement python-3.6