python floor函数的用法

摘自《python程序设计基础》蔡永铭主编
工具:python 3.7 64-bit
官方链接:https://www.python.org/
平台:Windows10

floor函数的使用

在python中使用函数之前需要了解一下模块的含义。
模块是一个包含所有定义的函数和变量的文件。模块可以被别的程序引入,以使用该模块中的函数等功能。

因为floor函数在math模块中,所以先得导入math模块,导入后才能使用math模块中floor的函数。
导入模块用法:import 模块
使用模块中函数用法:模块●函数

floor函数定义:将给定的数值转换成小于或等于它的最大整数(取不大于给定值的最大整数)。

import math  #这将导入math模块
print("math.floor(-45.7):",math.floor(-45.7))
print("math.floor(45.7):",math.floor(45.7))
print("math.floor(-100.5):",math.floor(-100.5))
print("math.floor(100.5):",math.floor(100.5))

结果:
math.floor(-45.7): -46
math.floor(45.7): 45
math.floor(-100.5): -101
math.floor(100.5): 100

解题思路:
在这里插入图片描述
作者:安东省心
时间:2019/8/7

原创文章 20 获赞 22 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_44687034/article/details/98772822
今日推荐