- 學習資料:
Python3 Tutorial
1. Interactive Shell
terminal$ python3
>>>
2. Execute .py Script
python fileName.py
Python is both an interpreted and a compiled language.
Python會自動檢查工作目錄的寫權限,如果沒有寫權限,那么編譯的代碼只會在程序執行的時候產生,程序退出,編譯的代碼就會被消除(相當于直接interpret而“未compile”)。如果有寫權限,那么編譯的代碼就會被存在.pyc
文件中。
編譯的代碼由PVM執行。
Compiler: to transform source code into executable program
Interpreter: (1) execute the source code directly or (2) translates the source code in a first step into a more efficient representation and executes this code
3. Python structures by colons and indentation
從語法上保證了程序的易讀性
4. Variables
- Numbers
Integer, Floating, Complex
- There is no "long int" in Python3 anymore, Integers in Python3 can be of unlimited size.
- true div:
/
; floor div://
- String
- All strings in Python 3 are sequences of "pure" Unicode characters
- ASCII: 128 characters
- Unicode: four bytes are possible per character
Immutable
比較
is
比地址;==
比內容- 一個奇怪之處:
"Hi" is "Hi" == true
"Hi!" is "Hi!" == False //含特殊字符
5. Operators
10 / 3 == 3.3333333333333335
10 // 3 == 3
10.0 // 3 == 3.0
10**3 == 1000