簡單講解Python中的數(shù)字類型及基本的數(shù)學計算
Python有四種類型的數(shù)字:
1.整型
a = 2 print a
2.長整型
b = 123456789 print b
3.浮點數(shù)
c = 3.2E2 print c
4.復數(shù) 復數(shù)為實數(shù)的推廣,它使任一多項式都有根。復數(shù)當中有個“虛數(shù)單位”j,它是-1的一個平方根。任一復數(shù)都可表達為x+yj,其中x及y皆為實數(shù),分別稱為復數(shù)之“實部”和“虛部”。
d = (2+3j) print d
計算示例:
每種程序語言都有數(shù)學計算方法,數(shù)學符號通用,大家都知道。直接上代碼吧:
print "I will now count my chickens:" print "Hens", 25 + 30 / 6 print "Roosters", 100 - 25 * 3 % 4 print "Now I will count the eggs:" print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6 print "Is it true that 3 + 2 < 5 - 7?" print 3 + 2 < 5 - 7 print "What is 3 + 2?", 3 + 2 print "What is 5 - 7?", 5 - 7 print "Oh, that's why it's False." print "How about some more." print "Is it greater?", 5 > -2 print "Is it greatet or equal?", 5 >= -2 print "is it less or equal?", 5 <= -2
運行結(jié)果應(yīng)該是這樣的:
root@he-desktop:~/mystuff# python ex3.py I will now count my chickens: Hens 30 Roosters 97 Now I will count the eggs: 7 Is it true that 3 + 2 < 5 - 7? False What is 3 + 2? 5 What is 5 - 7? -2 Oh, that's why it's False. How about some more. Is it greater? True Is it greatet or equal? True is it less or equal? False
eg:用數(shù)學計算把英寸和磅轉(zhuǎn)化為厘米和千克。
1英寸 = 2.54厘米,1磅 = 0.4536千克
my_height_centimeter = my_height * 2.54 my_weight_kilo = my_weight * 0.4536 print "He's %d centimeters tall." % my_height_centimeter print "He's %d kilos heavy." % my_weight_kilo
- Python的math模塊中的常用數(shù)學函數(shù)整理
- Python編程實現(xiàn)數(shù)學運算求一元二次方程的實根算法示例
- 詳解Python編程中基本的數(shù)學計算使用
- 用Python做的數(shù)學四則運算_算術(shù)口算練習程序(后添加減乘除)
- Python中的數(shù)學運算操作符使用進階
- Python3使用Matplotlib 繪制精美的數(shù)學函數(shù)圖形
- 使用Python的SymPy庫解決數(shù)學運算問題的方法
- Python使用matplotlib繪制多個圖形單獨顯示的方法示例
- Python實現(xiàn)在tkinter中使用matplotlib繪制圖形的方法示例
- Python使用matplotlib填充圖形指定區(qū)域代碼示例
- Python圖形繪制操作之正弦曲線實現(xiàn)方法分析
- Python數(shù)學形態(tài)學實例分析
相關(guān)文章
Python實現(xiàn)爬蟲抓取與讀寫、追加到excel文件操作示例
這篇文章主要介紹了Python實現(xiàn)爬蟲抓取與讀寫、追加到excel文件操作,結(jié)合具體實例形式分析了Python針對糗事百科的抓取與Excel文件讀寫相關(guān)操作技巧,需要的朋友可以參考下2018-06-06
關(guān)于你不想知道的所有Python3 unicode特性
我的讀者知道我是一個喜歡痛罵Python3 unicode的人。這次也不例外。我將會告訴你用unicode有多痛苦和為什么我不能閉嘴。我花了兩周時間研究Python3,我需要發(fā)泄我的失望。在這些責罵中,仍然有有用的信息,因為它教我們?nèi)绾蝸硖幚鞵ython3。如果沒有被我煩到,就讀一讀吧2014-11-11

