python中的關(guān)鍵字
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
python中的注釋
單行注釋:#
多行注釋:#,'...',"..."
***縮進的空格可變,但是同一個代碼塊的語句必須包含相同的縮進空格
多行語句
使用\,在{}[]()中不需要\
數(shù)字類型
int、 bool、 float、complex(復數(shù)形2+3j)
字符串(String)
字符串可以用 + 運算符連接在一起,用 * 運算符重復。
'a'+'b'? ?ab??'a'*2 # 輸出aa
兩種索引 左到右 0 右到左-1開始
print('hello\nrunoob') # 使用反斜杠(\)+n轉(zhuǎn)義特殊字符
打印hello 換行nrunoob
print(r'hello\nrunoob') # 在字符串前面添加一個 r,表示原始字符串,不會發(fā)生轉(zhuǎn)義
打印hello\nrunoob
import sys; x = 'runoob'; sys.stdout.write(x + '\n')#可以一行有行語句;隔開
print 默認輸出是換行的,如果要實現(xiàn)不換行需要在變量末尾加上 end="":
print('a’)
print('a',end="")#不換行
import 與 from...import #導入相應的模塊
將整個模塊(somemodule)導入,格式為:import somemodule
從某個模塊中導入某個函數(shù),格式為:from somemodule import somefunction
從某個模塊中導入多個函數(shù),格式為:from somemodule import firstfunc, secondfunc, thirdfunc
將某個模塊中的全部函數(shù)導入,格式為:from somemodule import *
標準數(shù)據(jù)類型
不可變數(shù)據(jù)(3 個):Number(數(shù)字) int、float、bool、complex(復數(shù))。
String(字符串)、
Tuple(元組);
可變數(shù)據(jù)(3 個):List(列表)、Dictionary(字典)、Set(集合)。
>>> isinstance(B(), A)? True? #isinstance()會認為子類是一種父類類型。
>>> type(B()) == A? ? ? ?False???type()不會認為子類是一種父類類型。