python内置函数三
2024-09-03 13:20:22
ord() 函数 和 chr() 相反 chr() 是将数字转换成assci码 ord() 是将字符串转换成assci码 显示
pow() 函数 pow(x,y,z) 表示x**y%z 取商。 如果是pow(x,y) 表示x**y
例如: print(pow(2,3)) print(pow(2,3,2)) 输出: 8 0
reverse() 函数 翻转,将一个列表进行掉头。例如:
num = [1,2,3,4,5,6,7,8,9]
num.reverse()
print(num)
输出:
[9, 8, 7, 6, 5, 4, 3, 2, 1]
round() 四舍五入
slice() 定义切片的规则 例如:
a = "hello"
s1 = slice(3,5)
print(a[s1])
输出:
lo
可以提前定下规则,方便以后的阅读代码
还可以指定步长,例如:
a = "abcdefghijklmnopqrstuvwxyz"
s1 = slice(3,11,2)
print(a[s1])
输出:
dfhj
最新文章
- ajax携带状态值
- java项目报junit 相关错误
- bzoj1201: [HNOI2005]数三角形
- BOOST的AUTO link机制以及配置
- SQL中CONVERT()转化函数的用法 字符串转日期
- Python基本程序结构
- A题笔记(11)
- linux内核--进程地址空间(三)
- POJ1836 Alignment(LIS)
- springMVC3学习(八)--全局的异常处理
- Windows 10 IoT Core环境配置中的那些坑
- 使用webpack热加载,开发多页面web应用
- libGDX-wiki发布
- VMware workstation创建虚拟机console
- 长短时记忆网络LSTM和条件随机场crf
- 3ds max学习笔记(十)-- 实例操作(镜像和对齐)
- Eclipse出现:An internal error occurred during: ";Retrieving archetypes:";. GC overhead limit exceeded的问题解决
- .NET MVC5+ Dapper+扩展+AutoFac自动注入实现
- Python3之socket编程
- [LeetCode&;Python] Problem 136. Single Number
热门文章
- 进程,内存,管理 ps,pstree,top,free,vmstat,iftop,lsof,查看网速
- Cisco AP-如何调整LAP信道
- office365激活码序列号密钥:
- 从零构建以太坊(Ethereum)智能合约到项目实战——学习笔记10
- 四阶幻方-蓝桥杯-DFS
- Python数据类型-7 bytes
- 建小程序 - 报Error: EPERM : operation not permitted, scandir mac下改变一个目录的访问权限
- linux中cp指令前面加反斜杠
- 使用eclipse搭建springboot项目pom.xml文件第一行报错(Maven Configuration Problem)
- centos6.5安装图形操作界面