Things need to be noticed — Python

tan21098
2 min readSep 9, 2020

1, else statement

else can appear with for and while blocks.

else block will automatically run after a loop successfully terminates.

Note that the first for loop did not successfully terminate, so else block will not be executed

2, Sequence

List, Tuple, String

Note: Dict is not a sequence, because it has no order and can’t be indexed

3, Keywords Arguments are preferred to Positional Arguments

We can unpack a sequence or dict with * or ** in setting arguments

4, Mutable data structures should not be the default parameters for a function

Python’s default arguments are evaluated once when the function is defined, not each time the function is called.

5, Python searches a variable in order of [Local, Enclosed, Global, Built-in]

Locals are often inside a function.

Enclosed are often a function wrapped in another function.

Globals are often the script level.

Built-in are special names that Python reserves for itself.

--

--