Python输入或原始输入(2.7.15)

2024-04-24 22:47:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python还不熟悉。我正在开发MacOS,我有python2.7.15。你知道吗

我正在尝试从用户那里获取输入:

#these two rows do not execute at the same time, it's just an example :)
annee = raw_input("Saisissez une annee : ") #works if input is string, but not if it's int
annee = input("Saisissez une annee : ") #works if input is int, but not if it's string
try:
    anne = int(annee)
    # isBissextile(annee)
except:
    print("Erreur lors de la saisie")

正如我在评论中所说,input和raw\u输入没有按预期工作,我希望能够获得int或string输入,然后显示exception或not


Tags: 用户inputstringrawifisnotit