python内置函数大全

#!/usr/bin/python
# -*- coding utf8 -*-

'''
abs()	dict()	help()	min()	setattr()
all()	dir()	hex()	next()	slice()
any()	divmod()	id()	object()	sorted()
ascii()	enumerate()	input()	oct()	staticmethod()
bin()	eval()	int()	open()	str()
bool()	exec()	isinstance()	ord()	sum()
bytearray()	filter()	issubclass()	pow()	super()
bytes()	float()	iter()	print()	tuple()
callable()	format()	len()	property()	type()
chr()	frozenset()	list()	range()	vars()
classmethod()	getattr()	locals()	repr()	zip()
compile()	globals()	map()	reversed()	__import__()
complex()	hasattr()	max()	round()	 
delattr()	hash()	memoryview()	set()
'''
#abs()  #绝对值
bo = all([1,2,3])  #取出所有的对象判断布尔值  如果所有为True返回True
print(bo)
bo=all('')#空也为True
print(bo)
print(any([0, None, '', 1])) #取出所有对象判断布尔值  一个为真则为真
print(any(''))                #空值为False

print(bin(10))   #10转2进制
print(hex(17))      #转16
print(oct(9))   #转8进制

#bool()   0 None 空为False 其余为True
def func():
    pass
print(callable(func))#判断是否可调用对象
print(chr(68)) #ascii转换
print(ord('d')) #ascii转换
#后续讲内置函数
# classmethod
# staticmethod
# property

res = complex(1+2j)
print(res.real)
print(res.imag)
#结果位1.0 2.0  复数的实部 虚部

#面向对象反射
# delattr
# hasattr
# getattr()
# setattr()

#工厂函数
# dict
# int
# str
# set
# list






#2

#!/usr/bin/python
# -*- coding utf8 -*-
l=[]
print(dir(l))#查看目录下的属性
#print(help(l))#帮助信息

print(divmod(10,3)) #除法  可以用于分页的计算
#执行结果(3, 1)

cmd = 'print("你愁啥")'
eval(cmd)   #执行字符串中命令  取消字符串格式

#eval简单示例  字符串转字典
dic="{'a':1,'b':2}"
d=eval(dic)
with open('a.txt','w',encoding='utf-8') as f:
    user_dic={'name':'xp','age':22}
    f.write(str(user_dic))
with open('a.txt','r',encoding='utf-8') as f:
    dic = f.read()
    print(dic, type(dic))
    dic = eval(dic)
    print(d,type(d))


#map  reduce filter   下文

#frozenset()  定义不可变集合
s={1,2}
s.add(3)
print(s)
s=frozenset({1,2})

s='{}{}{}'.format('xp',18,180)
print(s)

print(hash('dddddsdadfaasf')) #hash值
'''
1.只要校验内容一致 , 那hash结果永远一致
2.不可逆
3.只要采用的哈希算法一样,那无论被校验内容长度多少 结果都一致
'''
x=1
y=x
print(id(x),id(y))
print(x is y) #身份运算符
print(x==y) #判断值



#面向对象
#isinstance()
#issubclass()
#len 长度
#list 列表
#max 最大


'''
max
min
sorted

'''
#ord ascii表反推

print(pow(10,2,3))  #前2个平方 和第三个取余

#repr()   相比str更适合机器
#reversed  反转成迭代器

l = ['a',2,3,4]
for i in reversed(l):
    print(i)
print(list(reversed(l)))  #list sum  tuple也都支持迭代器协议

i = reversed(l)
for x in i:
    print(x)
print(list(i))  #迭代器迭代完毕 没有值

print(round(3.1415926535897932,5))  #round 保留小数位数,四舍五入


#slice 切片  重复利用
l=[1,2,3,4,5]
print(l[1:4])#第二个到第4个  也可指定步长
s = slice(1,4,2)
print(l[s])

#vars  无参 和 locals()一样
        # 有参数 __dict__


#zip  拉链 只找能对应上的
s='hello'
l=[1,2,3,4,5]
z=zip(s,l)
print(z)
for i in z:
    print(i)
'''
zip拉链执行结果  
('h', 1)
('e', 2)
('l', 3)
('l', 4)
('o', 5)
'''
#__import__
# import time


__import__('time') #以字符串的形式导入模块
#或者
m='time'
__import__(m)


m=__import__('time')
m.sleep(3)  #m也支持导入模块的功能


#面向对象里补充
# super
#
# isinstance
# issubclass
#
#
# classmethod
# staticmethod
# property
#
# delattr
# hasattr
# getattr
# setattr
#












  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 以下是 Python3 内置函数的完整列表: - abs() - all() - any() - ascii() - bin() - bool() - breakpoint() - bytearray() - bytes() - callable() - chr() - classmethod() - compile() - complex() - delattr() - dict() - dir() - divmod() - enumerate() - eval() - exec() - filter() - float() - format() - frozenset() - getattr() - globals() - hasattr() - hash() - help() - hex() - id() - input() - int() - isinstance() - issubclass() - iter() - len() - list() - locals() - map() - max() - memoryview() - min() - next() - object() - oct() - open() - ord() - pow() - print() - property() - range() - repr() - reversed() - round() - set() - setattr() - slice() - sorted() - staticmethod() - str() - sum() - super() - tuple() - type() - vars() - zip() 除此之外,还有一些 Python 内置模块,例如 `math`,`datetime`,等等也包含很多有用的函数。 ### 回答2: Python内置函数是指在Python编程语言中已经定义好的、可以直接使用的函数。以下是Python内置函数大全表: 数值处理函数: - abs():返回一个数的绝对值。 - divmod():将两个数相除并返回商和余数。 - pow():返回一个数的指定次幂。 - round():将一个数四舍五入到指定的小数位数。 字符串处理函数: - len():返回字符串长度。 - str():将数值转换为字符串。 - format():格式化字符串。 - split():将字符串按照指定的分隔符切片成列表。 列表处理函数: - len():返回列表长度。 - max():返回列表中的最大值。 - min():返回列表中的最小值。 - sum():返回列表中所有元素的和。 字典处理函数: - len():返回字典中键值对的数量。 - keys():返回字典中所有的键。 - values():返回字典中所有的值。 - items():返回字典中所有的键值对。 文件处理函数: - open():打开一个文件并返回文件对象。 - write():向文件中写入内容。 - read():从文件中读取内容。 - close():关闭文件。 其他常用函数: - type():返回对象的类型。 - range():生成一个指定范围的整数序列。 - print():打印输出内容到控制台。 - input():接收控制台输入。 以上是一些常见的Python内置函数,可以在Python的官方文档中找到完整的内置函数列表。 ### 回答3: Python是一种功能强大的编程语言,拥有丰富的内置函数,用于完成各种任务。以下是Python内置函数大全表: 1. 数学函数:比如abs()用于取绝对值,sum()用于求和,pow()用于幂运算等。 2. 字符串函数:比如len()用于计算字符串的长度,str()用于将其他类型转换为字符串,upper()用于将字符串转换为大写等。 3. 列表函数:比如len()用于计算列表的长度,max()用于找出列表中的最大值,sorted()用于对列表进行排序等。 4. 字典函数:比如len()用于计算字典中键值对的个数,keys()用于获取字典中所有的键,values()用于获取字典中所有的值等。 5. 文件函数:比如open()用于打开文件,read()用于读取文件内容,write()用于向文件写入内容等。 6. 类型转换函数:比如int()用于将其他类型转换为整数,float()用于将其他类型转换为浮点数,str()用于将其他类型转换为字符串等。 7. 输入输出函数:比如input()用于获取用户输入内容,print()用于输出内容到控制台。 8. 布尔函数:比如bool()用于将其他类型转换为布尔值,isinstance()用于判断一个对象的类型等。 9. 时间函数:比如time()用于获取当前时间戳,sleep()用于暂停脚本的执行一段时间等。 10. 迭代器函数:比如iter()用于创建一个迭代器对象,next()用于获取迭代器的下一个值等。 以上仅列举了一部分Python内置函数,还有很多其他函数可以根据需要进行查阅。这些内置函数Python编程的基础,掌握它们能够帮助我们更高效地完成各种任务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值