在raw_input()中使用中文提示,在CMD下中文乱码问题解决。。。

错误的程序及结果:

image

image 

image

解决1:

guess = int(raw_input('请输入一个整数:'.decode('utf-8').encode('gbk')))

image

解决2:

guess = int(raw_input(unicode('请输入一个整数:','utf-8').encode('gbk')))

image

此处python 版本 2.7.11,编译器 sublime 3

注意:

python 中出现中文一般需要加前缀 u 或 U 用来避免乱码,但只对 print 有效,对 raw_input 无效(或者我没有找到解决方法)

原文地址:https://www.cnblogs.com/blueskylcc/p/5329990.html