Python 2.X-关于函数返回的数值类型

时间:2023-03-08 22:00:01

在使用同一个函数,相同的参数的时候,参数在传递的过程中使用了不同的形式(有无小数点)决定了该函数返回的值的类型。

# -*- coding:utf-8 -*-

def return_types(one, two):
return (one / two) int_type = return_types(3, 2)
print "%f" % int_type float_type = return_types(3.0, 2.0)
print "%f" % float_type

下面为运行结果。

 1.000000
1.500000