简述python中的数字类型有哪些_Python中的数字类型都有哪些?

本文介绍了Python中的四种数字类型:整型、长整型、浮点数和复数,并通过代码示例展示了它们的使用。此外,还演示了Python中的数学运算,包括算术操作和逻辑判断。文章最后提出了将英寸和磅转换为厘米和千克的计算方法。
摘要由CSDN通过智能技术生成

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 <= -2

运行结果应该是这样的:

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:用数学计算把英寸和磅转化为厘米和千克。

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

本文地址:http://www.45fan.com/a/question/43250.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值