Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用格式功能对齐宽东亚字符_Python_Unicode - Fatal编程技术网

Python 使用格式功能对齐宽东亚字符

Python 使用格式功能对齐宽东亚字符,python,unicode,Python,Unicode,我正在使用pythonformat方法在终端显示中对齐。下面的python3代码说明了我的问题 ZH_STRING1 = "東京大学" ZH_STRING2 = "麻将" print(">" + "01234567" + "<") print(">" + format(ZH_STRING1, ">4") + "<") print(">" + format(ZH_STRING2, ">4") + "<") print("---") print("L

我正在使用python
format
方法在终端显示中对齐。下面的python3代码说明了我的问题

ZH_STRING1 = "東京大学"
ZH_STRING2 = "麻将"

print(">" + "01234567" + "<")
print(">" + format(ZH_STRING1, ">4") + "<")
print(">" + format(ZH_STRING2, ">4") + "<")
print("---")
print("Length:         ", len(ZH_STRING2))
ZH_STRING1=”東京大学"
ZH_STRING2=”麻将"

打印(“>”+“01234567”+”+格式(ZH_STRING1,“>4”)+”+格式(ZH_STRING2,“>4”)+”事实上,我在写这个问题时找到了一个解决方案^^

它非常简单:在python
format
函数中使用Unicode表意空间(U+3000),这将占用终端输出上的正常空间:

ZH_STRING1 = "東京大学"
ZH_STRING2 = "麻将"

print(">" + "01234567" + "<")
print(">" + format(ZH_STRING1, " >4") + "<")
print(">" + format(ZH_STRING2, " >4") + "<")
ZH_STRING1=”東京大学"
ZH_STRING2=”麻将"
打印(“>”+“01234567”+”+格式(ZH_STRING1,” >4“+”+格式(ZH_STRING2,” >4") + "