如何使用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 红包祝福语简短10字
18 周六早晨祝福语简短