python检查数值

2024-04-26 12:53:41 发布

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

我有一个表单值:

anytext = request.POST.get("my_text", None)
if anytext and anytext.is_string:
    perform any action
if anytext and anytext.is_numeric:
    perform another action

如何检查数值??在


Tags: andtextnone表单getstringifis
2条回答

你可以试试:

 if int(re.search(r'\d+', anytext).group())):
    #perform action

您可以使用isdigit(),假设anytext总是string类型。在

例如:

'Hello World'.isdigit()  # returns False
'1234243'.isdigit()  # returns True

你的代码:

^{pr2}$

相关问题 更多 >