【发布时间】:2020-04-02 15:13:17
【问题描述】:
我一直在尝试遍历列表以找到第一个包含数字的项目。
我遇到了any(),它似乎无法“搜索”列表项目中的数字。
如果我以下面的列表为例:
["Hello", "World(2)", "Bye 3"]
列表中包含数字的第一项位于位置 1 [World(2)]。
第一次出现“携带”数字后的以下某些项目是否不相关。
我从以下开始:
list1 = ["Hello", "World(2)", "Bye 3"]
for x in list1:
if x is.digit(): #this method doesn't work because it's only true when the whole item contains numbers.
x = first_item_where_a_number_appears
如果有人能给出正确方法的提示,那就太好了。
【问题讨论】:
标签: python string list for-loop integer