習題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