python 不熟的语法5

1. python的库可以分为三类:自己写的库,用pip下载的库,python自带的库。

2. python package index(PyPI),里面有大量的库,还可以往里上传自己的库。

3. 如果函数没有指定返回值,那么函数将返回None:

>>> var = print(5)
5
>>> print(var)
None

4. 字典的键值不能是list,dict,set,因为它们是不可哈希的类型(unhashable type)。这个哈希跟数据结构里的哈希查找是一样的,使用哈希可以提高数据的查找速度。

>>> a = {[1, 2]:3}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'

5. 字典也可以用in和not in,用来看字典的键值集合中是否存在某个值。

>>> dic = {1:"one", 2:"two", 3:"three"}
>>> 1 in dic
True
>>> 4 not in dic
True

猜你喜欢

转载自blog.csdn.net/xia_ri_xing/article/details/84403455
今日推荐