Convert English Numbers to Persian in Python
This Snippet is coded by a user inOnline python Compiler. You can see and run this code too.
زبان: python
This Python script converts English digits (0-9) to Persian (Farsi) digits (۰-۹) in any given input. It uses a dictionary to map each digit and a function that converts the input to a string, processes each character, and joins them back. If the input is not convertible, it returns the original value.
Key features:
- Works with both integers and strings.
- Preserves non-digit characters (like separators or Persian text).
- Simple and easy to modify.
Example usage: convert_eng_num_to_fa(4352) returns "۴۳۵۲", and convert_eng_num_to_fa("13 تیر 1405") returns "۱۳ تیر ۱۴۰۵".