当前位置: 首页 > article >正文

python学习——常用的内置函数汇总

文章目录

  • 类型转换函数
  • 数学函数
  • 常用的迭代器操作函数
  • 常用的其他内置函数

类型转换函数

在这里插入图片描述

数学函数

在这里插入图片描述

常用的迭代器操作函数

在这里插入图片描述实操:

from cv2.gapi import descr_of

lst = [55, 42, 37, 2, 66, 23, 18, 99]

# (1) 排序操作
asc_lst = sorted(lst) # 升序
desc_lst = sorted(lst, reverse=True) # 降序
print(asc_lst)
print(desc_lst)

# (2) reversed 倒序
new_lst = reversed(lst)
print(new_lst)
print(list(new_lst))

# (3) zip
x = ['a', 'b', 'c', 'd', 'e']
y = [1, 2, 3, 4, 5]
zipobj = zip(x, y)
print(zipobj)
print(list(zipobj))

# (4) enumerate
enum = enumerate(y, start=1)
print(list(enum))

# (5) all
lst2 = [10, 20, '', 30]
print(all(lst2))
lst2 = [10, 20, '有空即为false', 30]
print(all(lst2))

# (6) any
lst2 = ['', '', '', '']
print(any(lst2))
lst2 = [10, 20, '全空即为false', 30]
print(any(lst2))

# (7) next
zipped = zip(x, y)
print(next(zipped))
print(next(zipped))
print(next(zipped))
print(next(zipped))

# (8) filter
def fun(n):
    return n % 2 == 1 # 奇数为True, 偶数为False
obj =  filter(fun, [1, 2, 3, 4, 5]) # 函数作参数时不用参数
print(list(obj))

# (9) map
def upper(s):
    return s.upper()
new_lst2 = ['hello', 'world']
obj2 = map(upper, new_lst2) # 函数作参数时不用参数
print(list(obj2))

常用的其他内置函数

在这里插入图片描述

# (1) format()
print(format(3.14, '20')) # 数值默认右对齐
print(format('3.14', '20')) # 字符串默认左对齐
print(format('3.14', ' <20')) # 左对齐
print(format('3.14', ' >20')) # 右对齐
print(format('3.14', ' ^20')) # 居中对齐
print(format(3.1415926, '.2f')) # 保留两位小数
print(format(20, 'b')) # 二进制
print(format(20, 'o')) # 八进制
print(format(20, 'x')) # 十六进制

# (2) len...

# (3) id...(查看内存地址)

# (4) type...

# (5) eval (字符串内数学运算)
print(eval('10+30'))
print(eval('10>30'))

http://www.kler.cn/a/528594.html

相关文章:

  • 图论——最小生成树
  • 2025一区新风口:小波变换+KAN!速占!
  • 【腾讯云】腾讯云docker搭建单机hadoop
  • Github 2025-01-25Rust开源项目日报Top10
  • 安卓逆向之脱壳-认识一下动态加载 双亲委派(二)
  • Pyside的QWebEngineProfile类
  • 2025年1月30日(Matlab 总结 `rm = 0:0.1:10;`)
  • 分析伏羲万年历
  • 4.攻防世界Web_php_include
  • 使用真实 Elasticsearch 进行高级集成测试
  • deep generative model stanford lecture note1 --- introduction
  • 8645 归并排序(非递归算法)
  • 工业相机如何获得更好的图像色彩
  • 常见数据丢失问题类型及解决方案
  • 前端 | 深入理解Promise
  • 蓝桥杯备赛经验帖
  • 图书管理系统 Axios 源码 __删除图书功能
  • Linux命令(144)之diff
  • [CVPR 2022]Cross-view Transformers for real-time Map-view Semantic Segmentation
  • Spring Boot项目如何使用MyBatis实现分页查询
  • 90,【6】攻防世界 WEB Web_php_unserialize
  • python-leetcode-完全二叉树的节点个数
  • webrtc协议详细解释
  • 完美还是完成?把握好度,辨证看待
  • 洛谷 P10289 [GESP样题 八级] 小杨的旅游 C++ 完整题解
  • 开发指南093-平台底层技术网站