一直有接觸Python,前段時間還買了兩本書打算學習學習,但總是因為各種各樣的原因而沒有堅持下來,囫圇吞棗般的翻了幾次書后干脆都扔一邊不想動了。最近好好反省了一下,決定正式從零開始學習Python,通過寫博客的方式敦促自己和記錄學習心得。
一、Windows平台安裝Python
1、在官網 https://www.python.org/,根據系統版本下載Python安裝包,這里我選擇的最新版-Python 3.6.0

2、雙擊下載好的exe文件進行安裝

這里我們選擇自定義安裝

全勾上就行了,next

根據需要選擇,建議前五項全部勾選;安裝路徑根據個人喜好即可,我選擇安裝在E盤。選擇完畢點擊Install

等待安裝完成----

安裝完成后,我們可以通過Python自帶的IDLE和終端窗口開始使用Python,也可以使用Win+R組合鍵,輸入cmd打開命令提示符窗口,再輸入python進入交互式終端。

國際慣例,第一次給 "hello,world!"。
二、Linux平台安裝Python
1、以CentOS 7 為例,通常Linux系統都會自帶Python2.6或2.7,在終端輸入python即可進入Python交互式解釋器。

2、安裝python-3.6.0
首先安裝可能需要的依賴包 yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel

然后到官網找到下載路徑,使用wget下載: wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz

下載后解壓,並將解壓后的文件夾放到/usr/local目錄下,同時刪除原有python依賴
# tar -zxvf Python-3.6.0.tgz # mv Python-3.6.0 /usr/local # ll /usr/bin | grep python # rm -rf /usr/bin/python

進入Python目錄,並執行 ./configure檢查配置

編譯,make
編譯安裝,make install

建立新的軟鏈接 # ln -s /usr/local/bin/python3.6 /usr/bin/python

更改yum腳本、/usr/bin/gnome-tweak-tool 以及 /usr/libexec/urlgrabber-ext-down 配置文件的python依賴
# cd /usr/bin

更改以上文件的頭文件 #!/usr/bin/python 為 #!/usr/bin/python2

至此,Python3.6已經安裝完畢,hello,world!
--------------------------------------------------------------------------------------------------------------------------
彩蛋:《Python之禪》

The Zen of Python, by Tim Peters
《Python之禪》 Tim Peters
Beautiful is better than ugly.
優美勝於丑陋
Explicit is better than implicit.
明了勝於隱晦
Simple is better than complex.
簡潔勝於復雜
Complex is better than complicated.
復雜勝於混亂
Flat is better than nested.
扁平勝於嵌套
Sparse is better than dense.
寬松勝於緊湊
Readability counts.
可讀性很重要
Special cases aren't special enough to break the rules.
即便是特例,也不可違背這些規則
Although practicality beats purity.
雖然現實往往不那么完美
Errors should never pass silently.
但也不應該放過任何異常
Unless explicitly silenced.
除非你確定需要如此
In the face of ambiguity, refuse the temptation to guess.
如果存在多種可能性,不要猜測
There should be one-- and preferably only one --obvious way to do it.
肯定有一種--通常也是唯一一種--最佳的解決方案
Although that way may not be obvious at first unless you're Dutch.
雖然這並不容易,因為你不是Python之父
Now is better than never.
動手比不動手要好
Although never is often better than *right* now.
但不假思索就動手還不如不做
If the implementation is hard to explain, it's a bad idea.
如果你的方案很難懂,那肯定不是一個好方案
If the implementation is easy to explain, it may be a good idea.
如果你的方案很好懂,那肯定是一個好方案
Namespaces are one honking great idea -- let's do more of those!
命名空間非常有用,我們應該多加利用
參考文檔:http://blog.csdn.net/hobohero/article/details/54381475
《Python語言及其應用》--[Bill Lubanovic] 著;丁嘉瑞 梁傑 禹常隆 譯
