社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Charif DZ

Charif DZ 最近创建的主题
Charif DZ 最近回复了
s = r'abc123d, hello 3.1415926, this is my book'
print re.findall(r'-?[0-9]+(?:\.[0-9]*)?|-?\.[0-9]+',s)

你不需要 escape 使用时两次 raw mode .

输出: ['123', '3.1415926']

返回类型还将是 strings 。如果希望返回类型为 integers floats 使用 map

import re,ast
s = r'abc123d, hello 3.1415926, this is my book'
print map(ast.literal_eval,re.findall(r'-?[0-9]+(?:\.[0-9]*)?|-?\.[0-9]+',s))

输出: [123, 3.1415926]

5 年前
回复了 Charif DZ 创建的主题 » 如何在python中将int打印为words seq

试试这个:

table=['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
number = input()

# loop over the input string to get number by number
for x in number:
     # now get the string representation from its index in table
    print(table[int(x)], end=' ')

输出:

684
six eight four

586493
five eight six four nine three