如何使用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 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短