Home > Backend Development > Python Tutorial > How to input Chinese in python

How to input Chinese in python

爱喝马黛茶的安东尼
Release: 2019-06-22 15:28:02
Original
11429 people have browsed it

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.

How to input Chinese in python

For example:

name = raw_input("What's your name?")
print "Hello, "+name+"!"
raw_input("Press enter")
Copy after login

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("按回车键退出!")
Copy after login

, 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("按回车键退出!")
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template