COMP9021 Jupyter Notebook Sheet

2017-07-30  本文已影响0人  Sisyphus235

Built_in(s)

1.Type and Classes

bool(0)
>>> False
bool(1.2) + bool(-1.2)
>>> 2

coding使用isinstance()作为判别条件的时候,要小心:
isinstance(True, bool) --> True
isinstance(False, bool) --> True
isinstance(True, int) --> True
isinstance(False, int) --> True

2.Literal Representation

complex("2")
>>> 2+0j
complex("2+3j") #字符串中+前后不能有空格
>>>2+3j
complex(2.3, 2.3)
>>>2.3+2.3j
complex(1, 2).conjugate()
>>>1-2j
complex(1, 2.1).real
>>>1.0
complex(2.1, 2).imag
>>>2.0

Nonlocal. Nonlocal is similar in meaning to global. But it takes effect primarily in nested methods. It means "not a global or local variable." So it changes the identifier to refer to an enclosing method's variable.

上一篇 下一篇

猜你喜欢

热点阅读