python - 如何从 Python 中的原始输入中提取某些数字?

标签 python regex string

假设我向用户询问一些随机字母和数字。假设他们给了我 1254jf4h。我如何将字母 jfh 转换为一个单独的变量,然后将数字 12544 转换为一个单独的变量?

最佳答案

>>> s="1254jf4h"
>>> num=[]
>>> alpah=[]
>>> for n,i in enumerate(s):
...   if i.isdigit():
...      num.append(i)
...   else:
...      alpah.append(i)
...
>>> alpah
['j', 'f', 'h']
>>> num
['1', '2', '5', '4', '4']

关于python - 如何从 Python 中的原始输入中提取某些数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3896368/

相关文章:

python - 如何从位于 Odoo 11 表单操作下拉列表中的按钮发送电子邮件?

python - PyQt QMediaPlayer setPosition 对位置值进行四舍五入

python - 循环运行的 python 程序的 HTML 界面

python - 如何将字符串值格式化为实际字符串

ruby 正则表达式 : split string with match beginning with either a newline or the start of the string?

python - 使用鼠标模拟时出现 TypeError : a bytes-like object is required, 而不是 'str'

python - 类似Win32风格的pyqt Window

Javascript - RegExp - 替换最后一次出现的非数字

ruby - ruby 1.9.3 与 2.0.0 中的正则表达式负前瞻

Javascript如何跳过基于空格分隔符的拆分,除了特定序列后面的空格