Python快速入門_1

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.