python区分数字和字符串的解决方法 [英] python distinguish number and string solution
本文介绍了python区分数字和字符串的解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是python的新手,正在尝试解决数字和字符串的区别例如:
I'm new to python and trying to solve the distinguish between number and string For example :
- 输入:111aa111aa
- 输出:数字:111111,字符串:aaaa
推荐答案
这是你的答案对于数字
import re
x = '111aa111aa'
num = ''.join(re.findall(r'[\d]+',x))
对于字母
import re
x = '111aa111aa'
alphabets = ''.join(re.findall(r'[a-zA-Z]', x))
这篇关于python区分数字和字符串的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文