Specify input() type in Python?

后端 未结 2 977
余生分开走
余生分开走 2020-12-06 21:41

Is it possible to define input times, like time, date, currency or that should be verified manually? Like for example:

morning = input(\'Enter morning Time:\         


        
2条回答
  •  旧巷少年郎
    2020-12-06 21:59

    input (in Python 2.any) will return the type of whatever expression the user types in. Better (in Python 2.any) is to use raw_input, which returns a string, and do the conversion yourself, catching the TypeError if the conversion fails.

    Python 3.any's input works like 2.any's raw_input, i.e., it returns a string.

提交回复
热议问题