Python
Syntax
-
from ... import ... as ...
import 的后面内容对本模块可见
package1.package2.module.name只要import涉及到package,该package下的__init__.py 会被自动执行
package
is a folder, containing many python files and __init__.pymodule.py
is a python file in the packagename
is afinc,var,class
ofmodule.py
from package.package import module from package.package import module.name from package.package.module import name from . import module # `.` 代表当前模块的目录, 入口模块中 `.` 代表 __main__ from .package import module
绝对导入的参照物是入口模块,相对导入的参照物是当前模块
在Python2.6前默认为相对导入,之后默认为绝对导入
-
Library install
# 在线安装,在CMD窗口中运行 easy_install pandas pip install pandas # pip是easy_install的改进版 # whl文件离线安装,在CMD窗口运行 pip install xxxxx.whl # 压缩包离线安装,在CMD窗口运行 python setup.py install
Annex A. Syntax Summary
C/C++ | MAtlab | PYTHON | |
---|---|---|---|
create | a[10] | [1,2] | List:[1,2] |
IndexFrom | 0 | 1 | 0 |
Row/Col | [][major] | [major][] | [][major] |
if-else | else if | elseif | elif |
relation | ==,!=,>= | ==,~=,>= | ==,!=,>= |
logic | &&,||,! | &&,!!,~ | and,or,not |
(element-wise) | - | & | ~ |
(bit-wise) | & | ^,~ | bitand |
shift | <<,>> | - | <<,>> |
power | pow(a,b) | a^b | a**b |
rem | a%b | rem(a,b) | a%b |
ndims(t) | t.ndim | ||
size(t) | t.shape | ||
numel(t) | t.size | ||
A .* B | A * B | ||
A * B | A @ B | ||