- 学习资料:
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
网友评论