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
int
operands, 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**2
returns100
, but10**-2
returns0.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) 如果元组.列表里面的所有元素都非 ...
随机推荐
- 关于Selenium3+python3.6自动化测试中iframe切换
本篇内容主要表述以下几个问题: 1.iframe 这个是什么? 2.定位iframe 标签时遇到的几个报错总结. 3.显示等待与隐示等待的原理与优缺点. 4.无name,ID可变情况下的处理方式 5. ...
- JIRA
https://www.jianshu.com/p/8c14b52ce692 JIRA这个工具接触有好几年了,在多个海外项目上都用过这个工具.去年又在项目上深度使用后就有点爱不释手了,回国后也在找机会 ...
- TensorFlow卷积网络常用函数参数详细总结
卷积操作 tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None) 除去name参数用以指定该操作 ...
- 1.3 正则表达式和python语言-1.3.6匹配多个字符串
1.3.6 匹配多个字符串(2018-05-08) 我们在正则表达式 bat|bet|bit 中使用了择一匹配(|)符号.如下为在 Python中使用正则表达式的方法. import re #bat| ...
- linux 安装mysql5.7版本
首先准备好mysql5.7.17的安装包,安装包放在 /data/software 目录下 进入到 /usr/local 目录下,解压mysql安装包 命令: cd /usr/local tar ...
- Android应用程序的结构和解析
什么是Android应用程序的构成? Android应用程序的各个组件又是什么? 各个组件和AndroidManifest之间的关系是什么? Android应用程序由松散耦合的组件组成,并使用应用程序 ...
- mysql数据表增删改查
http://www.runoob.com/mysql/mysql-tutorial.html 一.MySQL 创建数据表 创建MySQL数据表需要以下信息: 表名 表字段名 定义每个表字段 语法 以 ...
- Hive管理表分区的创建,数据导入,分区的删除操作
Hive分区和传统数据库的分区的异同: 分区技术是处理大型数据集经常用到的方法.在Oracle中,分区表中的每个分区是一个独立的segment段对象,有多少个分区,就存在多少个相应的数据库对象.而在P ...
- python学习:continue及break使用
continue及break使用 #continue 作用:结束本次循环,继续下次循环#break 作用:跳出整个当次循环 for i in range(10): if i < 5: conti ...
- 多阶段构建Docker镜像
在Docker 17.05及更高的版本中支持支持一种全新的构建镜像模式:多阶段构建: 多阶段构建Docker镜像的最大好处是使构建出来的镜像变得更小: 目前常见的两个构建镜像的方式为: 1.直接使用某 ...