Home > Article > Backend Development > How to input Chinese in python
I just came into contact with the Python language. When I was practicing, I found that Chinese characters could not appear in the script (Chinese is not supported in Python2. The script will crash and cannot be run.
For example:
name = raw_input("What's your name?") print "Hello, "+name+"!" raw_input("Press enter")
Related recommendations: "Python Video Tutorial"
The simple code above is It can run, but if we change the display to:
name = raw_input("你叫什么名字?") print "你好, "+name+"!" raw_input("按回车键退出!")
, it will not run. So if you want to input Chinese into the python script, enter in the first line of the code: #coding= utf-8
looks like this:
#coding=utf-8 name = raw_input("你叫什么名字?") print "你好, "+name+"!" raw_input("按回车键退出!")
or enter:
# -*- coding: UTF-8 -*-
The above is the detailed content of How to input Chinese in python. For more information, please follow other related articles on the PHP Chinese website!