初識python
python勃黍,當(dāng)今十大熱門語言之一,更是機器學(xué)習(xí)的領(lǐng)先者
python于1989年阱飘,由荷蘭人Guido van Rossum(吉多·范羅蘇姆)發(fā)明
吉多給python的定位是簡單屏镊,高效针史,使得python易學(xué)習(xí),易閱讀赋访,易維護可都,從而成為受歡迎的語言,其他關(guān)于python的前世今生我也就不過多描述了蚓耽,百度一下很全面渠牲,下面我們開始這一章的內(nèi)容,初識python田晚。
一· python能干什么
python什么都能做嘱兼,比如web開發(fā),爬蟲開發(fā)贤徒,數(shù)據(jù)分析芹壕,游戲開發(fā),自動化接奈,人工智能等等踢涌,俗話說,人生苦短序宦,我用python睁壁,python在手,天下我有。
二· python版本的選擇
眾所周知潘明,python有2.x和3.x的版本行剂,python官網(wǎng)推薦使用3.x的版本,本系列教程也將使用python3.6的版本钳降。
Short version: Python 2.x is legacy, Python 3.x is the present and future of the language
三·python安裝
- mac安裝
mac自帶的是python2.7的版本厚宰,需要再安裝一個3.6的
官網(wǎng)下載地址:python3.6.3
百度云盤下載:python3.6.3 提取密碼: cvzp
安裝過程默認即可 - windows安裝
官網(wǎng)下載地址:python3.6.3
百度云盤下載:python3.6.3 提取密碼:tuqq
安裝過程默認即可
(由于官網(wǎng)下載可能會比較慢,百度云盤鏈接是本人從官網(wǎng)下載然后上傳到百度遂填,請放心下載)
四·python交互式環(huán)境
python的交互式是一個很好用的調(diào)試工具铲觉,也做為我們認識python程序的一個入口。
- windows系統(tǒng)打開cmd吓坚,輸入python撵幽,然后回車
-
mac系統(tǒng)打開terminal,輸入python礁击,然后回車
python交互式環(huán)境
(由于我是mac系統(tǒng)盐杂,有兩個版本的python,所以進入3.x系統(tǒng)使用的是python3這個命令)
接下來哆窿,我們就可以在交互式環(huán)境下玩一玩python了况褪,下面是一些例子,對于它們的具體用法可自行百度更耻,或者等待后面的教程慢慢學(xué)習(xí)测垛,這里的目的只是為了幫助認識python。
# 打印當(dāng)前時間
>>> import time
>>> time.ctime()
'Sun Oct 15 23:52:52 2017'
>>> time.time()
1508083060.4198642
# 基礎(chǔ)運算
>>>2 ** 10
1024
>>>25 - 12
13
>>>25 / 2
12.5
>>> "A" * 72
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
# 打印字符串
>>>print("Hello world!")
Hello world!
# python禪道
>>>import this
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!
四·python代碼文件編寫
python代碼文件以py作為文件的后綴名秧均,我們把剛才在交互式輸入的語句寫入到python代碼文件中食侮。
first.py
import time
print(time.ctime())
print(time.time())
print(2 ** 10)
print(25 - 10)
print(25 / 2)
print("A" * 72)
print("Hello World!")
import this
之后通過python命令來運行它,windows在cmd里面目胡,mac在terminal里面
執(zhí)行python first.py锯七,就會得到如下結(jié)果
Mon Oct 16 00:09:03 2017
1508083743.0646641
1024
15
12.5
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Hello World!
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!
五·小結(jié)
本章簡單介紹了python的用途,安裝運行python誉己,python交互式環(huán)境的使用眉尸,以及python代碼文件的編寫和執(zhí)行,目的是為了讓大家對python有個初步的了解巨双,下一章節(jié)將會為大家介紹python變量噪猾,數(shù)據(jù)類型相關(guān)的基本知識。
本人第一次寫文章筑累,如有不對的地方請多多指教袱蜡。