【发布时间】:2015-06-19 17:10:20
【问题描述】:
我是 Python 的新手。我正在制作一个程序,我从用户那里获取输入并检查字符串中是否有任何数字。我通过将它放入一个变量来检查它。通过 VARIABLE 进行检查不正确吗?
user_string=input("Enter the Word:")
print (user_string)
for index in (0,9):
number=str(index) #Typecasting Int to String
if number in user_string: #Check if Number exist in the string
print ("yes")
输出:
Enter the Word:helo2
helo2
【问题讨论】:
-
如果有数字怎么办?
-
你是在寻找特定的数字,所有的数字,每次遇到一个数字时要打印yes吗?
-
任何数字,正如 Daniel 问题正确强调的那样,都在 for 循环中。对于范围内的数字(10),效果很好
标签: python python-3.x