第5节--python数据类型--numeric

本文深入探讨了Python的数值类型,包括无限长度的int、基于double的float以及包含实部和虚部的complex。通过sys.float_info可以获取float的相关信息。详细运算规则可参考官方文档。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、python数据类型

2、例子

import sys

a = 3
b = 4

c = 5.66
d = 8.0


e = complex(c,d)
f = complex(float(a),float(b))
# f = complex(a,b)

print("a is type: ",type(a))
print("c is type: ",type(c))
print("e is type: ",type(e))

print(a+b)
print(d/c)

print(b/a)
print(b//a)

print(e)
print(e+f)

print ("e's real part is: " , e.real)
print ("e's imaginary part is: " , e.imag)

print(sys.float_info)

运行结果:

a is type:  <class 'int'>
c is type:  <class 'float'>
e is type:  <class 'complex'>
7
1.4134275618374559
1.3333333333333333
1
(5.66+8j)
(8.66+12j)
e's real part is:  5.66
e's imaginary part is:  8.0
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值