Python讀書筆記

2022-09-11 08:36:13 字數 1243 閱讀 8729

第一章 python基礎

tuple又叫元組(),一旦初始化就不可再改變

dict又叫字典,d = 2

set和dict類似,也是一組key的集合,但不儲存value。由於key不能重複,所以,在set中,沒有重複的key。s = set([1, 1, 2, 2, 3, 3]);set可以看成數學意義上的無序和無重複元素的集合,因此,兩個set可以做數學意義上的交集、並集等操作:s1 & s2;s1 | s2

第二章 函式

要注意定義可變引數和關鍵字引數的語法:

*args是可變引數,args接收的是乙個tuple;

**kw是關鍵字引數,kw接收的是乙個dict。

第三章 高階特性

>>> [x * x for x in range(1, 11)]

[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

>>> [m + n for m in

'abc

'for n in

'xyz']

['ax', '

ay', '

az', '

bx', '

by', '

bz', '

cx', '

cy', '

cz']

t = (b, a + b) # t是乙個tuple

a = t[0]

b = t[1]

第四章 函式式程式設計

map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9])

reduce(f, [x1, x2, x3, x4]) = f(f(f(x1, x2), x3), x4)

第六章 物件導向程式設計

class

student(object):

def__init__

(self, name, score):

self.

__name =name

self.

__score =score

defprint_score(self):

print('

%s: %s

' % (self.__name, self.__score))

其中函式__init__用於構造物件,第乙個引數self是固定的

python讀書筆記

numpy篇 numpy.around 函式返回指定數字的四捨五入值 numpy.floor numpy.floor 返回小於或者等於指定表示式的最大整數,即向下取整 numpy.ceil numpy.ceil 返回大於或者等於指定表示式的最小整數,即向上取整 numpy.reciprocal nu...

python讀書筆記

python有六個標準的資料型別 1.number 數字 int,float,bool,complex 2.string 字串 3.tuple 元祖 4.list 列表 5.dictionary 字典 6.sets 集合 迭代器 迭代器物件從集合的第乙個元素開始訪問,直到所有的元素被訪問完結束。迭代...

python讀書筆記 一

一,python語法8要素 usr bin env python3 print hello world 資料型別 int 45 str 912 使用 hard times 5 物件引用 x bule y green z x 元組使用逗號建立 tuple denmark finland norway ...