標籤:erp post format 布爾 判斷 算術 ble 浮點 未經處理資料類型
注釋
# 用#號字元開頭注釋單行""" 三個引號可以注釋多行 三個引號可以注釋多行 三個引號可以注釋多行"""
未經處理資料類型和運算子(1)整型
#整數3 #=>3
(2)算術運算
#加法1+1 #=>2#減法8-1 #=>7#乘法10*2 #=>20#除法 !!!結果自動轉換成浮點數35/5 #=>7.05/3 #=>1.6666666666666667#整數除法 !!!結果向下取整5//3 #=>15.0//3.0 #=>1.0-5//3 #=>-25//(-3) #=>-2-5.0//3.0 #=>-2.0#浮點數的運算結果也是浮點數3*2.0 #=>6.0#模數7%3 #=>1#x的y次方2**4 #=>16#用括弧決定優先順序(1+3)*2 #=>8
(2)布爾運算與比較運算
#布爾值True #=>TrueFalse #=>False#用not取非not True #=>Falsenot False #=>True#邏輯運算子,注意and和or都是小寫True and False #=>FalseTrue or False #=>True#整數也可以當做布爾值0== False #=>True2==True #=>False1==True #=>True#用==判斷相等1==1 #=>True2==1 #=>False#用!=判斷不等1!=1 #=>False1!=2 #=>True#比較大小1<10 #=>True#比較大小1<10 #=>True2<=2 #=>True2>=2 #=>True
(4)算術運算
#字串用單引號雙引號都可以‘這個是字串‘"這個也是字串"#用加號連接字串‘Hello ‘+‘World‘ #=>‘Hello World‘#字串可以被當做字元列表‘This is a string‘[0] #=>‘T‘#用format來格式化字串"{} can be {}".format("string",‘interpolated‘) #=>‘string can be interpolated‘#可以重複參數以節省時間"{0} be nimble,{0} be quick,{0} jump over the {1}".format("jack","candle stick") #=>‘jack be nimble,jack be quick,jack jump over the candle stick‘#如果不想數參數可以用關鍵詞"{name} wants to eat {food}".format(name=‘Bob‘,food=‘lasagna‘) #=>‘Bob wants to eat lasagna‘#如果你的python3程式也要運行在Python2.5以下環境運行,也可以用老式的格式化文法"%s can be %s the %s way"%(‘strings‘,‘interpolater‘,‘old‘) #=>‘strings can be interpolater the old way‘(2)None
#None是一個對象None#當與None進行比較時不要用==,要用is,is是用來比較兩個變數是否指向同一個對象‘etc‘ is None #=>FalseNone is None #=>True#None,0,Null 字元串,空列表,空字典都算是False,其他都是Truebool(None) #=>Falsebool(0) #=>Falsebool("") #=>Falsebool({}) #=>Falsebool([]) #=>False
Python快速入門_1