python中常用内置函数用法总结

强制类型转换:
int()
float()
str()
list()
tuple()
set()
dict()
总结,这几种类型转换函数得用法基本一致,基本就是int(要转换得数据)。返回值类型为对应得数据类型

max():求多个参数的最大值,或可迭代对象中的最大元素
min():最小值
sum():求和,可迭代对象元素求和
pow():求幂,pow(2, 3)等价于2 ** 3
round():四舍五入,可以指定保留位数

hex():16进制
oct():8进制
bin():2进制

print:打印,输出
input:输入
abs:求绝对值
type:获取变量的类型
chr:将ASCII数值转换为字符
ord:将字符转换为对应的ASCII
id:获取变量地址
len:统计元素个数
range:产生连续整数的可迭代对象
enumerate:枚举可迭代对象

原文地址:https://www.cnblogs.com/chaojiyingxiong/p/9174893.html

时间: 2024-07-29 01:59:30

python中常用内置函数用法总结的相关文章

Python中常用内置函数介绍(filter,map,reduce,apply,zip)

Python是一门很简洁,很优雅的语言,其很多内置函数结合起来使用,可以使用很少的代码来实现很多复杂的功能,如果同样的功能要让C/C++/Java来实现的话,可能会头大,其实Python是将复杂的数据结构隐藏在内置函数中,只要写出自己的业务逻辑Python会自动得出你想要的结果.这方面的内置函数主要有,filter,map,reduce,apply,结合匿名函数,列表解析一起使用,功能更加强大.使用内置函数最显而易见的好处是: 1. 速度快,使用内置函数,比普通的PYTHON实现,速度要快一倍左

python中的内置函数getattr()

在python的官方文档中:getattr()的解释如下: getattr(object, name[, default]) Return the value of the named attribute of object. name must be a string. If the string is the name of one of the object’s attributes, the result is the value of that attribute. For examp

Python中的内置函数__init__()的理解

有点意思,本来我是学习java的.总所周知,java也有构造函数,而python在面向对象的概念中,也有构造函数.它就是 __init__(self) 方法. 其实类似于__init__()这种方法,其实还有很多.类似__del__(self)  ...  __new__(cls,*args,**kwd) 等等.它们被成为 python的常用内置方法. 下面开始介绍一下我对 __init__()的理解: class A(object): def __init__(self,name):  sel

python之常用内置函数

python内置函数,可以通过python的帮助文档 Build-in Functions,在终端交互下可以通过命令查看 >>> dir("__builtins__") ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', ',_eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__g

Python中max()内置函数使用(list)

在学习完列表和元组的基础知识后,做到一个题: 求出列表中频次出现最多的元素. 学习到了python内置函数max的用法 其参数key的用法 匿名函数lamda的用法 python内置函数max() max()方法返回给定参数的最大值,参数值可为序列. 1 print ("max(80, 100, 1000) : ", max(80, 100, 1000)) 2 print ("max(-20, 100, 400) : ", max(-20, 100, 400)) 3

python中的内置函数getattr()介绍及示例

在python的官方文档中:getattr()的解释如下: ? 1 2 3 getattr(object, name[, default]) Return the value of the named attribute of object. name must be a string. If the string is the name of one of the object's attributes, the result is the value of that attribute. F

python中的内置函数(bytearray)

返回一个新的字节数组.bytearray类是range 0 < = x < 256的一个可变序列.它有大多数可变序列的常用方法,在可变序列类型中描述,以及大多数字节类型的方法,参见字节和Bytearray操作. 可选的源参数可以用几种不同的方式来初始化数组: 如果它是一个字符串,那么您还必须给出编码(以及可选的错误)参数;bytearray()然后使用str.encode()将字符串转换为字节. 如果它是一个整数,那么数组将具有这个大小,并将用null字节初始化. 如果它是符合缓冲区接口的对象

python 中的内置函数

1.输出函数 print() 1 print("hello world!") 2.输入函数 input() 1 a = input() 2 hello world 3 print (a) 3.chr()函数 该函数返回整形参数值所对应的Unicode字符的字符串 1 print(chr(916)) 2 print([chr(i) for i in range(870,8719)]) 4.ord()函数 返回单个字符的ASCⅡ值或者unicode 的值 1 print((功)) 2 pr

python中的内置函数

abs(number):取绝对值 1 re=abs(-342) 2 print(re) 3 #输出:342 all(iterable):判断可迭代的对象的元素是否都是真,如果是返回True 否则返回false ; 0,none,空 都是假 li=[12,43,23,] re=all(li) print(re) #输出:True li=[12,43,23,0] re=all(li) print(re) #输出:False bin(number):将number转换成二进制的数并返回 re=bin(