Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How does python enter Chinese? How do I Chinese in a py script?


May 29, 2021 Article blog



Many small partners in the beginning of learning the Python language will encounter script running process, can not use the Chinese, or even enter the Chinese after the flashback situation, today W3Cschool editor came to analyze how python input Chinese.

In fact, the reason for the flashback is related to the python version, which has added support for Chinese in the new version, but lower versions such as 2. Version X of python, there will be the script using Chinese will flash back.

If a flashback occurs while running the Python script, you can add code on the first #coding=utf-8

#coding=utf-8
name = raw_input("你叫什么名字?")
print "欢迎来到, "+name+"!"
raw_input("按回车退出")

Or add the code # -*- coding: UTF-8 -*- Adding both sets of code lets you use Chinese while running the Python script.

The above answers how Python enters Chinese, hoping to help you, and many more Python-related questions can be learned in our Python section.