在Python中指定input()类型? [英] Specify input() type in Python?

查看:606
本文介绍了在Python中指定input()类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以定义输入时间,例如时间,日期,货币或应该手动验证?例如:

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:')
evening = input('Enter evening Time:')

..我只需要时间,如何确保用户以xx:xx格式输入输入,其中xx仅是整数.

.. I need (only) time here, how do I make sure that user enters input in xx:xx format where xx are integers only.

推荐答案

input (在Python 2.any中)将返回用户键入的任何表达式的类型.更好的方法(在Python 2.any中)使用 Python 3.any的input的工作方式与2.any的raw_input相同,即,它返回一个字符串.

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

这篇关于在Python中指定input()类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆