Python
1 Introduction
1.1 Coding Style
- Use spaces around operators and after commas,
- Wrap lines so that they don't exceed 79 characters.
- Use 4-space indentation, and no tabs.
- Use blank lines to separate functions and classes, and larger blocks of code inside functions.
- When possible, put comments on a line of their own.
- Name your classes and functions consistently; the convention is to use
UpperCamelCase
for classes and lowercase_with_underscores
for functions and methods.- Always use
self
as the name for the first method argument.
Slice
object[start:stop:step]
切片内容不含冒号 (colon) 右边的索引。
反转列表或者字符串:
>>> word[::-1]
a[:, :, None] 和 a[..., None] 的输出是一样的。
Annotation (注释)
- docstring
- 单行注释, #
- 多行注释, """"""
2 dir() and help()
Expression
call expression
Statement
Function
Formal parameters, frame,