Python知識分享網(wǎng) - 專業(yè)的Python學(xué)習(xí)網(wǎng)站 學(xué)Python,上Python222
python知識點(diǎn)梳理(都是精華) PDF 下載
發(fā)布于:2024-03-13 11:33:13
(假如點(diǎn)擊沒反應(yīng),多刷新兩次就OK!)

python知識點(diǎn)梳理(都是精華) PDF 下載 圖1

 

 

 

資料內(nèi)容:

 

一、python 規(guī)范
1.命名規(guī)則
(1)必須以下劃線或字母開頭
(2)前后單下劃線為系統(tǒng)變量
(3)雙下劃線開頭為類的私有變量
(4)關(guān)鍵字不能用作變量名
2.注釋
• 單行注釋以 # 開頭
• 多行注釋可用多個(gè) # 或者用 三引號(文檔注釋)
3.多行語句
• 行尾使用反斜線(\) 來續(xù)行
4.同一行寫多條語句
• 語句間用分號(; ) 分隔
 
二、輸入輸出
1.輸出 print()
• print 默認(rèn)在末尾換行
a = 1
b = 2
c =3 # 直接輸出多個(gè)變量 print( a , b , c )
# 輸出: 1 2 3
# 使用 end 參數(shù)用指定的字符替換末尾的換行符 print( a , end =' @' )
# 輸出: 1@
# 使用 formatprint(' a={} ' . format( a ) ) # 輸出:
a=1print(' a={0} , b={1} , c{2} ' . format( a , b , c ) ) # 輸出: a=1
b=2, c3
2.輸入 input()
• input 輸入的始終是字符串, 需要轉(zhuǎn)換為其他數(shù)據(jù)類型使用
 
三、python 數(shù)據(jù)類型
1.六個(gè)標(biāo)準(zhǔn)數(shù)據(jù)類型
(1)Number(數(shù)字)
(2)String(字符串)
(3)List(列表)
(4)Tuple(元組)
(5)Sets(集合)
(6)Dictionary(字典)
2.Number
• 包括: int(整型) 、 float(浮點(diǎn)型) 、 bool(布爾型) 、 complex
(復(fù)數(shù)) 、 long(長整型)
• 清楚哪些值轉(zhuǎn)換為布爾類型后值是 False
print(bool([]) )
# 輸出: Falseprint(bool(' ' ) )
# 輸出: Falseprint(bool({} ) )
# 輸出: Falseprint(bool(() ) )
# 輸出: False# 注意下面兩個(gè)的區(qū)別
print(bool(0) )
# 輸出: Falseprint(bool(' 0' ) )
# 輸出: True
• 浮點(diǎn)數(shù)的內(nèi)置函數(shù)運(yùn)算會有誤差, 也就是小數(shù)的精度問題
3.String
字符串屬于序列, 除此之外還有:元組、列表(集合和字典不是序列類型)
單引號和雙引號可以互換, 也可以互嵌
三引號表示多行字符串(也可以作為文檔注釋
另外: 三引號內(nèi)可以直接使用回車、 制表符, 可以不使用轉(zhuǎn)移字符
來表示
字符串常用操作:
(1)連接和重復(fù)
print(‘hello’ *3, ’ wor’ +’ ld’ )
# 輸出: hellohellohello world
字符串的切片(左閉右開)
word = ' hello world' print( word [0: 5])
# 輸出: helloprint( word [: 5])
# 輸出: helloprint( word [1: ])
# 輸出: ello worldprint( word [: ])
# 輸出: helloworldprint( word [0: 5: 2])
# 輸出: hloprint( word [2: -2])
# 輸出: lloworprint( word [-2: 2])
# 輸出空串
(2)轉(zhuǎn)義字符
• 要注意這種復(fù)雜的轉(zhuǎn)義字符一起輸出
在字符串內(nèi)的“\r”、 ”\t”、 ”\n”等字符, 會轉(zhuǎn)換為空白字符(回車符、
水平制表符、換行符……)
printf(' hello\tworld' ) # 輸出: hello world
(3)Raw 字符串(字符串內(nèi)不轉(zhuǎn)義)
字符串前綴為’R’或‘r’
print(r‘hello\tworld’ ) # 輸出: hello\tworld