Accessing Bangla (UTF-8) string by index in Python

2019-08-29 19:03发布

I have a string in Bangla and I'm trying to access characters by index.

# -*- coding: utf-8 -*-
bstr = "তরদজ"
print bstr # This line is working fine
for i in bstr:
    print i, # question marks are printed

I don't know why it isn't working.

1条回答
成全新的幸福
2楼-- · 2019-08-29 19:21

Turn it into unicode:

>>> bstr = "তরদজ"
>>> for i in bstr.decode('utf-8'):
...     print i
... 
ত
র
দ
জ
查看更多
登录 后发表回答