HelloPython
程序Python 2.x
與 3.x
版本簡介Python
程序的三種方式
python
/ python3
ipython
PyCharm
HelloPython
程序Python
的開發.py
認識Python
目錄認識Python
目錄下新建 01-HelloPython.py
文件01-HelloPython.py
而且輸入如下內容:print("hello python") print("hello world")
01-HelloPython.py
$ python 01-HelloPython.py
python
中咱們學習的第一個 函數python
BUG
,是程序員在開發時很是常見的,初學者常見錯誤的緣由包括:
每個程序員都是在不斷地修改錯誤中成長的shell
pirnt("Hello world")
NameError: name 'pirnt' is not defined 名稱錯誤:'pirnt' 名字沒有定義
print
寫在一行SyntaxError: invalid syntax 語法錯誤:語法無效
每行代碼負責完成一個動做bash
IndentationError: unexpected indent 縮進錯誤:不指望出現的縮進
- Python 是一個格式很是嚴格的程序設計語言
- 目前而言,你們記住每行代碼前面都不要增長空格
目前市場上有兩個 Python 的版本並存着,分別是 Python 2.x
和 Python 3.x
編輯器
SyntaxError: Non-ASCII character '\xe4' in file 01-HelloPython.py on line 3, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 語法錯誤: 在 01-HelloPython.py 中第 3 行出現了非 ASCII 字符 '\xe4',可是沒有聲明文件編碼 請訪問 http://python.org/dev/peps/pep-0263/ 瞭解詳細信息
ASCII
字符只包含256
個字符,不支持中文- 有關字符編碼的問題,後續會講
* error 錯誤 * name 名字 * defined 已經定義 * syntax 語法 * invalid 無效 * Indentation 索引 * unexpected 意外的,不指望的 * character 字符 * line 行 * encoding 編碼 * declared 聲明 * details 細節,詳細信息 * ASCII 一種字符編碼
Python 2.x
與 3.x
版本簡介目前市場上有兩個 Python 的版本並存着,分別是 Python 2.x
和 Python 3.x
ide
新的 Python 程序建議使用
Python 3.0
版本的語法函數
Python
的早期版本,這是一個 較大的升級Python 3.0
在設計的時候 沒有考慮向下兼容
Python
版本設計的程序都沒法在 Python 3.0
上正常執行Python 2.x
的語法和庫Python 3.0
的遷移,容許使用部分 Python 3.0
的語法與函數Python 2.7
被肯定爲 最後一個Python 2.x 版本提示:若是開發時,沒法當即使用 Python 3.0(還有極少的第三方庫不支持 3.0 的語法),建議工具
- 先使用
Python 3.0
版本進行開發- 而後使用
Python 2.6
、Python 2.7
來執行,而且作一些兼容性的處理
python
/ python3
# 使用 python 2.x 解釋器 $ python xxx.py # 使用 python 3.x 解釋器 $ python3 xxx.py
Python 的解釋器 現在有多個語言的實現,包括:學習
CPython
—— 官方版本的 C 語言實現Jython
—— 能夠運行在 Java 平臺IronPython
—— 能夠運行在 .NET 和 Mono 平臺PyPy
—— Python 實現的,支持 JIT 即時編譯Shell
中直接輸入 Python 的代碼,會當即看到程序執行結果exit()
>>> exit()
在 python 解釋器中,按熱鍵 ctrl + d
能夠退出解釋器編碼
python shell
好用得多
bash shell
命令Python 3.x 使用的解釋器是 ipython3
要退出解釋器能夠有如下兩種方式:
exit
In [1]: exit
在 IPython 解釋器中,按熱鍵 ctrl + d
,IPython
會詢問是否退出解釋器
$ sudo apt install ipython
PyCharm
集成開發環境(IDE
,Integrated Development Environment)—— 集成了開發軟件須要的全部工具,通常包括如下工具:
PyCharm
是 Python 的一款很是優秀的集成開發環境PyCharm
除了具備通常 IDE 所必備功能外,還能夠在 Windows
、Linux
、macOS
下使用PyCharm
適合開發大型項目