20170129_python_Python程式設計實務_練習小記
Github:
Client: openSUSE Leap 42.2 with vi and PyCharm
昨天練習相關檔案
檔案: 2-3.py
# 匯入 requests
import requests
# 透過 requests.get 去抓 民視的網頁
www = requests.get( "http://m.ftv.com.tw/newslist.aspx?class=L" )
# 如果使用 print( www ) 會得到 網頁回覆, 例如 200
# 所以如果要列出網頁內容使用書上的 print( www.text )
print( www )
print( "=========================================" )
print( www.text )
檔案: 3-1.py
a, b = 2, 3
# 列出 a 以及 b
print( a, b)
# 將 a 與 b 交換
a, b = b, a
print( a, b)
檔案: 3-2.py
# 書上的作法是 a = range(5), 他其實是要列出 list 0 到 4
# 這個時候 print( a ) 在 python 3, 會出現 range(0, 5)
# 所以 python3 內的寫法, 如果要使用 a = range(5)來列出 list 0 - 4, 應該是 print( list(a) )
# 所以將程式碼改為
# 註解寫了中文在 python 好像就會產生 error, 先無視他吧
a = list( range(4) )
#print( a )
#print( list(a) )
# 同理可證 b
b = list( range(10, 15) )
# 不然 c = a + b 在 python 3 就會出現錯誤
c = a + b
print( "List a", a )
print( "List b", b )
print( "List a + List b", c )
Chapter 4
確認是否有安裝相關模組
主要練習為 python 3 版本
# zypper search numPy
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
--+--------------------------+--------------------------------------+-----------
| python-numpy | NumPy array processing for numbers-> | srcpackage
i | python-numpy | NumPy array processing for numbers-> | package
| python3-numpy | NumPy array processing for numbers-> | package
# zypper search python3-matplo
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
--+------------------------------+---------------------------------------------------------+--------
| python3-matplotlib | Plotting Library for Python | package
預設沒有安裝 python3 的 numpy 以及 matplotlib 模組
安裝相關模組
# zypper install python3-matplotlib python3-numpy
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 16 NEW packages are going to be installed:
libwebpmux1 python-Cycler python-Pillow python-functools32 python-matplotlib python-matplotlib-tk python-pyparsing
python-python-dateutil python-pytz python-tk python3-dateutil python3-matplotlib python3-numpy python3-pyparsing
python3-pytz python3-six
The following 2 recommended packages were automatically selected:
python-Pillow python-matplotlib-tk
16 new packages to install.
Overall download size: 79.1 MiB. Already cached: 0 B. After the operation, additional 154.7 MiB will be used.
Continue? [y/n/? shows all options] (y): Y
檔案: 4-1.py
# -*- coding: utf-8 -*-
# 目前沒有成功, 圖形介面沒有顯示, 後續再來研究
import numpy as np
import matplotlib.pyplot as pt
x = np.arange(0, 360)
y = np.sin(x * np.pi / 180.0)
pt.plot(x, y)
pt.xlim(0, 360)
pt.ylim(-1.2, 1.2)
pt.title("SIN function")
pt.show()
今天先這樣
~ enjoy it
星期日, 1月 29, 2017
20170129_python_Python程式設計實務_練習小記
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言