如何使用Python将数字转换为单词?
python中字符串类的构造函数,即str可以用于将数字转换为python中的字符串。例如,
i = 10050 str_i = str(i) print(type(str_i))
这将给出输出:
<class 'str'>
但是,如果您希望将整数转换为99到99之间的单词,则必须使用外部软件包或自己构建一个。pynum2word模块在此任务上非常出色。您可以使用安装
$ pip install pynum2word
然后按以下方式使用
>>> import num2word >>> num2word.to_card(16) 'sixteen' >>> num2word.to_card(23) 'twenty-three' >>> num2word.to_card(1223) 'one thousand, two hundred and twenty-three'
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短