欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

簡(jiǎn)單講解Python中的數(shù)字類(lèi)型及基本的數(shù)學(xué)計(jì)算

 更新時(shí)間:2016年03月11日 15:30:46   作者:lixiang0522  
這篇文章主要介紹了Python中的數(shù)字類(lèi)型及基本的數(shù)學(xué)計(jì)算,與其他語(yǔ)言一樣,除法相對(duì)復(fù)雜些,不過(guò)本文并未就此深入,需要的朋友可以參考下

Python有四種類(lèi)型的數(shù)字:
1.整型 

a = 2 
print a 

2.長(zhǎng)整型 

b = 123456789 
print b 

3.浮點(diǎn)數(shù) 

c = 3.2E2 
print c 

4.復(fù)數(shù) 復(fù)數(shù)為實(shí)數(shù)的推廣,它使任一多項(xiàng)式都有根。復(fù)數(shù)當(dāng)中有個(gè)“虛數(shù)單位”j,它是-1的一個(gè)平方根。任一復(fù)數(shù)都可表達(dá)為x+yj,其中x及y皆為實(shí)數(shù),分別稱(chēng)為復(fù)數(shù)之“實(shí)部”和“虛部”。  

d = (2+3j) 
print d 

 

計(jì)算示例:
每種程序語(yǔ)言都有數(shù)學(xué)計(jì)算方法,數(shù)學(xué)符號(hào)通用,大家都知道。直接上代碼吧:

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 


運(yùn)行結(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ù)學(xué)計(jì)算把英寸和磅轉(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  


相關(guān)文章

最新評(píng)論