呼伦贝尔市建设网站,长春网站制作招聘信息,百度登录页,怎么设置wordpress页面目录
一.Python pow 函数介绍二.Python pow 函数使用 案例 1#xff1a;pow 函数常规使用案例 2#xff1a;pow 函数所有的参数必须是数值类型#xff0c;不能是其他类型#xff0c;否则报错 TypeError案例 3:若果 x#xff0c;y 有一个浮点数#xff0c;则结果将转换为…目录
一.Python pow 函数介绍二.Python pow 函数使用 案例 1pow 函数常规使用案例 2pow 函数所有的参数必须是数值类型不能是其他类型否则报错 TypeError案例 3:若果 xy 有一个浮点数则结果将转换为浮点数 三.猜你喜欢 基础 Python 学习路线推荐 : Python 学习目录 Python 基础入门 一.Python pow 函数介绍
在 Python 中内置函数 pow 共有两个参数x 和 y并返回 xyx 的 y 次方 的值语法如下 参数介绍x — 数值表达式(整数或者浮点数)y — 数值表达式(整数或者浮点数)z — 数值表达式(整数或者浮点数)默认不设置z值返回值返回 xy(x的y次方)的值如果设置了z值,则再对结果进行取模,其结果等效于pow(x,y) %z
pow(x, y[, z])二.Python pow 函数使用
案例 1pow 函数常规使用
# !usr/bin/env python
# !usr/bin/env python
# -*- coding:utf-8 _*-Author:猿说编程
Blog(个人博客地址): www.codersrc.com
File:Python pow 函数.py
Time:2021/04/19 07:37
Motto:不积跬步无以至千里不积小流无以成江海程序人生的精彩需要坚持不懈地积累print(pow(2,5)) # 等价 2*2*2*2*2 32
print(pow(2,3)) # 等价 2*2*2 8
print(pow(2,3,5)) # 等价 2*2*2%5 8 % 5 3
print(2*2*2%5) # 等价 pow(2,3,5) 3
输出结果32
8
3
3案例 2pow 函数所有的参数必须是数值类型不能是其他类型否则报错 TypeError
# !usr/bin/env python
# !usr/bin/env python
# -*- coding:utf-8 _*-Author:猿说编程
Blog(个人博客地址): www.codersrc.com
File:Python pow 函数.py
Time:2021/04/19 07:37
Motto:不积跬步无以至千里不积小流无以成江海程序人生的精彩需要坚持不懈地积累print(pow(2,2))
产生异常:Traceback (most recent call last):File E:/Project/python_project/untitled10/123.py, line 18, in moduleprint(pow(2,2))
TypeError: unsupported operand type(s) for ** or pow(): int and str案例 3:若果 xy 有一个浮点数则结果将转换为浮点数
# !usr/bin/env python
# !usr/bin/env python
# -*- coding:utf-8 _*-Author:猿说编程
Blog(个人博客地址): www.codersrc.com
File:Python pow 函数.py
Time:2021/04/19 07:37
Motto:不积跬步无以至千里不积小流无以成江海程序人生的精彩需要坚持不懈地积累print(pow(2,3.2))
print(pow(2,3.0))
输出结果9.18958683997628
8.0三.猜你喜欢
Python for 循环Python 字符串Python 列表 listPython 元组 tuplePython 字典 dictPython 条件推导式Python 列表推导式Python 字典推导式Python 函数声明和调用Python 不定长参数 *argc/**kargcsPython 匿名函数 lambdaPython return 逻辑判断表达式Python 字符串/列表/元组/字典之间的相互转换Python 局部变量和全局变量Python type 函数和 isinstance 函数区别Python is 和 区别Python 可变数据类型和不可变数据类型Python 浅拷贝和深拷贝
未经允许不得转载猿说编程 » Python pow 函数