python提取字符串中的数字

简介: python提取字符串中的数字

利用正则表达式提取字符串中的数字


import re
str_ = "我11是个32字符串,我中4间有677数字88"
number = re.findall("\d+",str_)    # 输出结果为列表
# 列表中的数字的数据类型是str
# ['11', '32', '4', '677', '88']
number = [int(x) for x in number]  # 将str格式的数字转换成int
print(number)
# [11, 32, 4, 677, 88]
相关文章
|
7月前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
436 100
|
7月前
|
开发者 Python
Python中的f-string:高效字符串格式化的利器
Python中的f-string:高效字符串格式化的利器
605 99
|
7月前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
|
7月前
|
开发者 Python
Python f-strings:更优雅的字符串格式化技巧
Python f-strings:更优雅的字符串格式化技巧
|
7月前
|
开发者 Python
Python f-string:高效字符串格式化的艺术
Python f-string:高效字符串格式化的艺术
|
7月前
|
Python
使用Python f-strings实现更优雅的字符串格式化
使用Python f-strings实现更优雅的字符串格式化
|
8月前
|
索引 Python
python 字符串的所有基础知识
python 字符串的所有基础知识
452 0
|
8月前
|
Python
Python字符串center()方法详解 - 实现字符串居中对齐的完整指南
Python的`center()`方法用于将字符串居中,并通过指定宽度和填充字符美化输出格式,常用于文本对齐、标题及表格设计。
|
8月前
|
Python
Python中的f-string:更简洁的字符串格式化
Python中的f-string:更简洁的字符串格式化
423 92

推荐镜像

更多