python--運算子

來源:互聯網
上載者:User

標籤:emd   minus   coding   ash   sub   image   技術   int   multi   

+ plus 加號-----------------------------------
• - minus 減號-------------------------------
• / slash 整除----商-------------------------(乘除取餘的優先順序高於加減)
• * asterisk 乘號----------------------------
• % percent 取餘----餘數-----------------

• < less-than 小於符號
• > greater-than 大於符號
• <= less-than-equal 小於等號
• >= greater-than-equal 大於等於符號

 

美國我們用 PEMDAS 這個簡稱來輔助記憶,它的意思是“括弧、指數、乘、除、加、減”——
Parentheses Exponents Multiplication Division Addition Subtraction ——這也是 Python 裡的
運算優先順序。

首先看一個例子:

 1 #!/usr/bin/python 2 #coding:utf-8 3  4 print "I will study number" 5  6 print "feifei",20+30/6  #預期是25 7 print "juanjuan",100-25*3%4  #預期是97 8 print 3+2+1-5+4%2-1/3%4  #預期是1 9 print 3+2<5-7 #預期是false10 print 5>-2 #預期是true11 print 5>=-2 #預期是true12 print 5<=-2 #預期是false

結果:

 

python--運算子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.