Pythonで全角数字、全角アルファベットを半角に変換

ロウ
2022-01-25
ロウ
2022-01-25

全角数字、全角アルファベット → 半角

```
fullwidth_char = "".join(chr(0xff01 + i) for i in range(94))
halfwidth_char = "".join(chr(0x21 + i) for i in range(94))

fullwidth_to_halfwidth = str.maketrans(fullwidth_char, halfwidth_char)

string = "123ABC"
output = string.translate(fullwidth_to_halfwidth)
print(output) # 結果: 123ABC
```