Hàm tạo của lớp string trong Python, tức str, dùng để chuyển số thành chuỗi. Ví dụ,
i = 10050 str_i = str(i) print(type(str_i))
Kết quả:
Nhưng nếu muốn chuyển số thành từ như 99 thành ninety-nine, phải dùng gói ngoài hoặc tự viết. Module pynum2word khá tốt. Cài đặt bằng
$ pip install pynum2word
Dùng như sau
>>> import num2word >>> num2word.to_card(16) 'sixteen' >>> num2word.to_card(23) 'twenty-three' >>> num2word.to_card(1223) 'one thousand, two hundred and twenty-three'