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 (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,5)
32
>>> pow(2,3)
8
>>> pow(2,3,5)
3
>>>
2.所有的参数必须是数值类型,不能是其他类型。
>>> pow(2,'2')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'str'
>>>
3.若果x,y 有一个浮点数,则结果将转换为浮点数。
>>> pow(2,3.2)
9.18958683997628
>>> pow(2,3.0)
8.0
4.如果x,y 都是整数,则结果也是整数,如果 y 是负数,浮点数不能取摸,所以传入的参数 z 不能取摸。如果可选参数 z 传入了值,则x,y 必须为整数,且 y 不能 负数,
>>> pow(2,-1)
0.5
>>> pow(2,-2)
0.25
>>> pow(2,-10)
0.0009765625
>>>
>>> pow(2,-10,2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: pow() 2nd argument cannot be negative when 3rd argument specified
Python内置函数(5)——pow的更多相关文章
- 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 (co ...
- 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) 如果元组.列表里面的所有元素都非 ...
- 【转】python 内置函数总结(大部分)
[转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...
- python内置函数,匿名函数
一.匿名函数 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc = lambda n ...
- python 内置函数总结(大部分)
python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是pytho ...
- Python之路(第八篇)Python内置函数、zip()、max()、min()
一.python内置函数 abs() 求绝对值 例子 print(abs(-2)) all() 把序列中每一个元素做布尔运算,如果全部都是true,就返回true, 但是如果是空字符串.空列表也返回t ...
- python内置函数大全(分类)
python内置函数大全 python内建函数 最近一直在看python的document,打算在基础方面重点看一下python的keyword.Build-in Function.Build-in ...
随机推荐
- node nvm npm nrm 安装
http://cnodejs.org/topic/57f628098489e7ca69f4e839 //1.vim ~./bashrc 文件 把那两行配置代码加进入,然后按步骤执行 //console ...
- SIMD---MMX代码优化
单指令多数据流,即SIMD(Single Instruction, Multiple Data)指一类能够在单个指令周期内同时处理多个数据元素的指令集,利用的是数据级并行来提高运行效率,典型的代表由I ...
- Java中的代理模式--静态代理和动态代理本质理解
代理模式定义:为其他对象提供了一种代理以控制对这个对象的访问. 代理模式的三种角色: Subject抽象主题角色:抽象主题类可以是抽象类也可以是接口,是一个最普通的业务类型定义,无特殊要求. Real ...
- angularjs 缓存详解
一.什么是缓存 一个缓存就是一个组件,它可以透明地存储数据,以便未来可以更快地服务于请求. 缓存能够服务的请求越多,整体系统性能就提升得越多. 二.Angular 中的缓存 2.1 $cacheFac ...
- tp框架的url模式
tp框架url地址可以由以下四种 http://网址/index.php?m=XX&c=XX&a=XX 基本get模式 http://网址/index.php/模块/控制器/操作方 ...
- jquery ajax 返回的json对象 新增属性值(干货)
$.ajax({ type:"GEt'; url:"你的地址", data:{"你的字段","字段值"} success:funt ...
- Mysql使用规范文档 20180223版
强制:不允许在跳板机上/生产服务器上手工连接,查询或更改线上数据 强制:所有上线脚本必须先在测试环境执行,验证通过以后方可在生产环境执行. 强制:上线脚本的编码格式统一为UTF-8 强制:访问数据库需 ...
- 可视化:svg相关基础
01.svg的嵌入.html <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- 笔记:Maven 设置代理配置
如果公司基于安全因素考虑,要求使用通过安全认证的代理服务器访问因特网,这种情况夏,需要为 Maven 配置HTTP代理,才能让他正常访问外部仓库,配置代理服务器需要在~/.ms2/settings.x ...
- Explain
explain关键字 explain关键字一般放在SELECT查询语句的前面,用于描述MySQL如何执行查询操作.以及MySQL成功返回结果集需要执行的行数.explain 可以帮助我们分析 sele ...