说明

  在今天做int实现的过程中,官方函数的解释是将numeric转换为integer,就突然不明白,两个有啥区别。

numeric-数字类型包括:

  int,float,bool,complex

integer–整数,是numeric的一部分

实验

>>> a,b,c,d = 10,10.1,True,4+3j
>>> int(a)
10
>>> int(b)
10
>>> int(c)
1
>>> int(d)
Traceback (most recent call last):
  File "<pyshell#24>", line 1, in <module>
    int(d)
TypeError: can\'t convert complex to int   #但是对于复数是不行的,不能转换。
>>> 

 备注:通过实验可以知道,int能够转换整数,浮点数,布尔值为整数。

 

文档创建时间:2018年12月7日17:15:14

版权声明:本文为chuanzhang053原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/chuanzhang053/p/10083990.html