found = False
position = 0
while not found and position < len(inputString):
if inputString[position].isdigit():
found = True
else:
position += 1
if found:
print('first digit is at position', position)
else:
print('There are no digits in the string')
这是我发现的一个简单程序,用于查找输入字符串中的第一个数字。我无法理解的事情是......
if inputString[position].isdigit():
found = True
这个表达式究竟说明了什么,特别是inputString[position]部分。我们是否在寻找第一个数字的位置/索引值,然后将循环分解为下面的打印语句?
千巷猫影
慕无忌1623718
慕运维8079593
相关分类