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) 如果元组.列表里面的所有元素都非 ...
随机推荐
- 二.Nginx反向代理和静态资源服务配置
2018年03月31日 10:30:12 麦洛_ 阅读数:1362更多 所属专栏: nginx 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/M ...
- kafka写入hdfs
碰到的问题 (1)线程操作问题,因为单机节点,代码加锁就好了,后续再写 (2) 消费者写hdfs的时候以流的形式写入,但是什么时候关闭流就是一个大问题了,这里引入了 fsDataOutputStr ...
- linux系统优化配置
# 2 millions system-wide sysctl -w fs.file-max=2097152 sysctl -w fs.nr_open=2097152 echo 2097152 > ...
- Linux磁盘和文件系统管理
1.检测并确认新硬盘 挂载好新的硬盘设备并启动主机后,Linux系统会自动检测并加载该硬盘,无须额外安装驱动.执行“fdisk -l”命令即可查看,确认新增硬盘的设备名称和位置.作用:列出当前系统中所 ...
- 普通用户添加sudo权限
1.切换超级用户 su - root 2.编辑配置文件 vim /etc/sudoers ## Allow root to run any commands anywhere root ALL=(AL ...
- 如何修改SnipeIT的部分设置
作为一款开源的资产管理系统,Snipe-IT非常的好用又结实,但是原始设置对中国用户有些不方便,部分汉化没有完成,需要直接修改代码,下面把常用的修改记录如下: 1.修改资产打印标签中的文本名称 找到 ...
- c#坐标系互相转换
转自群友的博客:https://www.xiaofengyu.com/?p=108 群友的github地址:https://github.com/jfwangncs/GPSConvert 各种坐标系 ...
- mysql 语法积累
1.把一个表中的某一列赋值到另一个表中的某一列 update sfa_token,sfa_member set sfa_token.mainid = sfa_member.mainid where s ...
- GeoHash(Java实现)
package com.koubei.collect_script.demo; import java.util.ArrayList; import java.util.Arrays; import ...
- 4.21Linux(2)
2019-4-21 22:46:55 今天买了阿里云服务器1年的 116大洋!!! 但是有个服务器感觉很爽!!!!Linux系统还是很有意思的!!!! 直接贴上笔记! 越努力,越幸运!永远不要高估自己 ...