Python算術運算子,python算術

來源:互聯網
上載者:User

Python算術運算子,python算術
Python算術運算子

以下假設變數a為10,變數b為20:

運算子 描述 執行個體
+ 加 - 兩個對象相加 a + b 輸出結果 30
- 減 - 得到負數或是一個數減去另一個數 a - b 輸出結果 -10
* 乘 - 兩個數相乘或是返回一個被重複若干次的字串 a * b 輸出結果 200
/ 除 - x除以y b / a 輸出結果 2
% 模數 - 返回除法的餘數 b % a 輸出結果 0
** 冪 - 返回x的y次冪 a**b 輸出結果 20
// 取整除 - 返回商的整數部分 9//2 輸出結果 4 , 9.0//2.0 輸出結果 4.0

 

以下執行個體示範了Python所有算術運算子的操作:

#!/usr/bin/python = 21= 10= 0 = + bprint "Line 1 - Value of c is ", c = - bprint "Line 2 - Value of c is ", c = * bprint "Line 3 - Value of c is ", c = / bprint "Line 4 - Value of c is ", c = % bprint "Line 5 - Value of c is ", c = 2= 3= a**bprint "Line 6 - Value of c is ", c = 10= 5= a//bprint "Line 7 - Value of c is ", c

以上執行個體輸出結果:

Line 1 - Value of c is 31Line 2 - Value of c is 11Line 3 - Value of c is 210Line 4 - Value of c is 2Line 5 - Value of c is 1Line 6 - Value of c is 8Line 7 - Value of c is 2

 

聯繫我們

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