+
80
-

python如何提取字符串中的数字?

python如何提取字符串中的数字?


网友回复

+
0
-
#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*
str1='a34e 345 bcd 5he 78 xyz'
#提取单个数字
for s in str1:
    if s.isdigit():print (s)

#以空格分割的完整数字    
for s in str1.split():
    if s.isdigit():
        print ((s))

我知道答案,我要回答