Python-1-搭建編程環境

當前存在兩個版本的Python,Python2和Python3,一般來說,編程語言的迭代都是向前兼容的,但在Python中2和3卻不是這種關係,嚴格來說Python3更像是另起爐竈,官方文檔中也說了,後面會取消對Python2的更新,一般來說,新的開發首選Python3。

搭建編程環境

工慾善其事必先利其器,那麼首先就來看下Python的安裝吧,這裏安裝的是Python3,Windows版本。
下載地址:http://python.org/downloads/
選擇合適的版本進行安裝。
在安裝過程中,勾選“add python to path”,這樣就直接加到了系統path,在任何地方都可以執行python命令了。

安裝完成後,打開cmd命令行,輸入python,顯示出如下字樣,證明安裝配置成功

Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

退出命令行可以使用Ctrl + Z和輸入exit()

這時候就可以編輯python程序了,這裏驗證python的輸出語句,在命令行中輸入python代碼

print("hello python!")

此時按下回車便會得到執行結果

Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello python!")
hello python!
>>>

另外,也可以將代碼存儲在文件中,然後執行
例如,新建一個 hello_python.py 的文件,使用無格式文本編輯器打開,輸入

print("hello python!")

然後在命令行中執行

python hello_python.py

同樣會得到輸出結果,與命令行的輸出一致。

當無法得到與上述一致的結果時,肯定是某個地方出了問題,這時候就需要仔細檢查售後哪裏出現了錯誤了。

到此,python的編程環境搭建就介紹完畢了。另外,學習任何一門編程語言的最開始,最好都不要用IDE,逐漸熟悉這門語言以後,再使用IDE。IDE幫我們做了太多工作,一開始就使用IDE會造成對語言的基礎掌握不牢固,這裏推薦使用純文本編輯器(NotePad++,EditPlus,Sublime Text等)先學習,後邊稍微熟悉了再使用IDE。

Python倡導的精神

在Python命令行中輸入import this,會輸出一段話,這正是Python倡導的精神

The Zen of Python, by 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.
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!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章