Python内置函数(49)——pow
英文文档:
pow(x, y[, z])- Return x to the power y; if z is present, return x to the power y, modulo z (computed more efficiently than
pow(x, y) % z). The two-argument formpow(x, y)is equivalent to using the power operator:x**y. - The arguments must have numeric types. With mixed operand types, the coercion rules for binary arithmetic operators apply. For
intoperands, the result has the same type as the operands (after coercion) unless the second argument is negative; in that case, all arguments are converted to float and a float result is delivered. For example,10**2returns100, but10**-2returns0.01. If the second argument is negative, the third argument must be omitted. If z is present, x and y must be of integer types, and y must be non-negative.
- 说明:
- 1. 函数有两个必需参数x,y和一个可选参数z,结果返回x的y次幂乘(相当于x**y),如果可选参数z有传入值,则返回幂乘之后再对z取模(相当于pow(x,y)%z)。
>>> pow(2,3)
8
>>> 2**3
8 >>> pow(2,3,5)
3
>>> pow(2,3)%5
3
2. 所有的参数必须是数值类型。
>>> pow('',3)
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
pow('',3)
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
3. 如果x,y有一个是浮点数,则结果将转换成浮点数。
>>> pow(2,0.1)
1.0717734625362931
4. 如果x,y都是整数,则结果也是整数,除非y是负数;如果y是负数,则结果返回的是浮点数,浮点数不能取模,所有可选参数z不能传入值。
>>> pow(10,2)
100
>>> pow(10,-2)
0.01
>>> pow(10,-2,3)
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
pow(10,-2,3)
ValueError: pow() 2nd argument cannot be negative when 3rd argument specified
5. 如果可选参数z传入了值,x,y必须为整数,且y不能为负数。
>>> pow(2,3,5)
3 >>> pow(10,0.1,3)
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
pow(10,0.1,3)
TypeError: pow() 3rd argument not allowed unless all arguments are integers >>> pow(10,-2,3)
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
pow(10,-2,3)
ValueError: pow() 2nd argument cannot be negative when 3rd argument specified
Python内置函数(49)——pow的更多相关文章
- Python内置函数(5)——pow
英文文档: pow(x, y[, z]) Return x to the power y; if z is present, return x to the power y, modulo z (co ...
- Python内置函数(49)——isinstance
英文文档: isinstance(object, classinfo) Return true if the object argument is an instance of the classin ...
- 【转】python 内置函数总结(大部分)
[转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...
- python 内置函数总结(大部分)
python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是pytho ...
- Python内置函数(4)
Python内置函数(4) 1.copyright 交互式提示对象打印许可文本,一个列表贡献者和版权声明 2.credits 交互式提示对象打印许可文本,一个贡献者和版权声明的列表 3.delattr ...
- Python | 内置函数(BIF)
Python内置函数 | V3.9.1 | 共计155个 还没学完, 还没记录完, 不知道自己能不能坚持记录下去 1.ArithmeticError 2.AssertionError 3.Attrib ...
- python内置函数
python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...
- python 内置函数和函数装饰器
python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...
- Python 内置函数笔记
其中有几个方法没怎么用过, 所以没整理到 Python内置函数 abs(a) 返回a的绝对值.该参数可以是整数或浮点数.如果参数是一个复数,则返回其大小 all(a) 如果元组.列表里面的所有元素都非 ...
随机推荐
- ASP.NET Core 的 `Core` 有几种写法?
一.概述 本文将会根据情况持续更新. 作为一个 Framework,ASP.NET Core 提供了诸多的扩展点.使用内置的组件和默认的配置通常就能够满足部分需求,当需要扩展的时就需要先去找出这些扩展 ...
- 558. Quad Tree Intersection
https://leetcode.com/problems/quad-tree-intersection/description/ 我觉得是用意挺好的一题目.求两个四叉树的逻辑union,可惜测试用例 ...
- 单机千万级MQTT连接服务器测试报告
目标:测试创建1000万客户端连接到服务器端,服务器操作系统 Linux(任意一款发行版服务器版本).分别在两台硬件一样的服务器,其中一台用于服务器端运行,另一台用于创建千万客户端连接客户端机器.在硬 ...
- 防御xss 大致理解
前端 发送留言内容 包含 js 代码 后台 管理员 查看 留言 代码被执行 拿到cookie 成功登陆 解决办法 对录入 进行相关的过滤处理 其他解决方法 正在学习中
- Analisis of Hello2 source
GreetingServlet.java @WebServlet("/greeting") //为servelt指定URL pattern为:/greeting public cl ...
- 给Ionic写一个cordova(PhoneGap)插件
给Ionic写一个cordova(PhoneGap)插件 之前由javaWeb转html5开发,由于面临新技术,遂在适应的过程中极为挣扎,不过还好~,这个过程也极为短暂:现如今面临一些较为复杂的需求还 ...
- php 记录日志时 基础的日志格式
2019-02-19 11:29:56 /api/shop/shopManagements?shopId=undefined REQUEST:HTTP://mutest.drcloud.cn/mo ...
- 阿森纳vs托特纳姆热刺
阿森纳vs托特纳姆热刺之间进行的英格兰足球联盟杯比赛时间为2018年12月20日 03:45.本场比赛的亚盘初盘为阿森纳0.0,大小球初盘3.0,角球盘口10.5.在此之前,阿森纳和托特纳姆热刺两队进 ...
- Ubuntu安装MySQL和Python库MySQLdb步骤
一.安装MySQL服务器和客户端 执行以下命令: sudo apt-get install mysql-server-5.6 mysql-client-5.6 sudo apt-get install ...
- 真正的ddos防御之道,简单干脆有效!
话说,30G 就各种发博客 BB,唉,坦白说 ,博客园团队真心没见过世面 来 各位 先看图 啥意思呢? 就是哥的 最高防御是 600G. 没错,基本对当时的游戏没啥大的影响,10秒内恢复. 因为时间 ...