习题1--第一个程序
- Python print练习
- 执行过程中遇到问题及解决办法
一、Python print练习
- 按照习题1创建一个空文本,保存为.py格式,并通过ATOM编辑器打开,代码如下:
# -*- coding: utf-8 -*-
print "Hello World"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'
print "我们都是中国人"
- 使用powershell软件执行上述脚本
PS F:\python大师\习题>python .\ex1.py
Hello World
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.
我们都是中国人
二、执行过程中遇到问题及解决办法
- 脚本中有中文内容,运行报错
File ".\ex1.py", line 9
SyntaxError: Non-ASCII character '\xce' in file .\ex1.py on line 9, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
解决:代码最开始添加# -- coding: utf-8 -*-
- 脚本执行过程中中文内容打印为乱码
鎴戜滑鏉ヨ嚜涓浗
*解决:ATOM中按照如下设置》Packages》Setting View》Open》Core》File Encodig改为gbk
网友评论