简单讲解python中的数字类型及基本的数学计算

python有四种类型的数字:
1.整型

a = 2
print a

2.长整型

b = 123456789
print b

3.浮点数

c = 3.2e2
print c

4.复数 复数为实数的推广,它使任一多项式都有根。复数当中有个“虚数单位”j,它是-1的一个平方根。任一复数都可表达为x+yj,其中x及y皆为实数,分别称为复数之“实部”和“虚部”。

d = (2+3j)
print d

计算示例:
每种程序语言都有数学计算方法,数学符号通用,大家都知道。直接上代码吧:

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

Posted in 未分类