int 数字
- python 有3种数字类型
- int: 整数类型
- float: 浮点类型
- complex: 复数类型
int类型
1
2
3
4
5
6
7
|
#Int或整数是完整的数字,正数或负数,没有小数,不限制长度 a = 10 b = - 10 c = 4555555555555555555555 print ( ">>Int或整数是完整的数字,正数或负数,没有小数,不限制长度" ) print ( type (a), type (b), type (c)) print (a, b, c) |
Float类型
1
2
3
4
5
6
7
|
#Float:浮动或浮点数是包含小数的正数或负数,不限制长度 d = 12.00 e = - 12.21 f = 4555555555555.58 print ( ">>浮动或浮点数是包含小数的正数或负数,不限制长度" ) print ( type (d), type (e), type (f)) print (d, e, f) |
complex类型
1
2
3
4
5
6
7
|
#complex 复数用'j'作为虚部编写 g = 2 + 3j h = 7j i = - 7j print ( ">>complex 复数用'j'作为虚部编写 " ) print ( type (g), type (h), type (i)) print (g, h, i) |
int(),float(),complex()类型之间的转换
1
2
3
4
5
6
7
8
9
10
11
12
13
|
j = 12 k = 12.63 l = 3j print ( '>>int,float,complex类型之间的转换 ' ) print ( '>> 转成int' ) print ( int (k)) #print(int(l)) 复数转换为int会报错 print ( '>> 转成flaot' ) print ( float (j)) #print(float(l)) 复数转换为float会报错 print ( '>>转成complex' ) print ( complex (k)) print ( complex (j)) |
总结
本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注服务器之家的更多内容!
原文链接:https://blog.csdn.net/weixin_38931408/article/details/122695646