python内置方法,,1.abs取绝对值>
python内置方法,,1.abs取绝对值>
1.abs取绝对值>>> abs(9.8)9.8>>> abs(-9.8)9.8
2.dic()变为字典类型
>>> dict({"key":"value"}){‘key‘: ‘value‘}
3.help()显示帮助信息
>>> help(map)Help on class map in module builtins:class map(object) | map(func, *iterables) --> map object | | Make an iterator that computes the function using arguments from-- More --
4.min取数据中的最小值,max取数据中的最大值
print(min([3, 4, 2]))print(min("wqeqwe"))print(min((3, 6, 4)))print(max([3, 4, 2]))print(max("wqeqwe"))print(max((3, 6, 4)))E:\PythonProject\python-test\venvP3\Scripts\python.exe E:/PythonProject/python-test/BasicGrammer/test.py2e34w6Process finished with exit code 0
5.all()所有的为true,才返回true。空的列表返回true
print(all([1, 2, 0])) # 列表中的0是False,所以返回Falseprint(all([1, 2, 5])) # 列表中的所有值都是True,所以返回Trueprint(all([])) # 空的列表,all()返回trueprint(help(all))E:\PythonProject\python-test\venvP3\Scripts\python.exe E:/PythonProject/python-test/BasicGrammer/test.pyFalseTrueTrueHelp on built-in function all in module builtins:all(iterable, /) Return True if bool(x) is True for all values x in the iterable. If the iterable is empty, return True.NoneProcess finished with exit code 0
6.any()任意一个为true就返回true。空的列表返回false
any()列表中的任意一个为True,就返回Trueprint(any([1, 2, 0])) print(any([1, 2, 5])) # 列表中的任意一个是True,就返回Trueprint(any([])) # 空的列表,any()返回falseprint(help(any))E:\PythonProject\python-test\venvP3\Scripts\python.exe E:/PythonProject/python-test/BasicGrammer/test.pyTrueTrueFalseHelp on built-in function any in module builtins:any(iterable, /) Return True if bool(x) is True for any x in the iterable. If the iterable is empty, return False.NoneProcess finished with exit code 0
7.dir()打印当前程序的所有变量
print(dir()) # 打印当前程序的所有变量E:\PythonProject\python-test\venvP3\Scripts\python.exe E:/PythonProject/python-test/BasicGrammer/test.py[‘__annotations__‘, ‘__builtins__‘, ‘__cached__‘, ‘__doc__‘, ‘__file__‘, ‘__loader__‘, ‘__name__‘, ‘__package__‘, ‘__spec__‘]Process finished with exit code 0
8.hex()把十进制数转换为16进制数
hex()转换为16进制print(hex(16)) E:\PythonProject\python-test\venvP3\Scripts\python.exe E:/PythonProject/python-test/BasicGrammer/test.py0x10Process finished with exit code 0
9.slice()切片
>>> l = [2,3,4,5,6,7]>>> s = slice(1,5,2)>>> l(s)Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: ‘list‘ object is not callable>>> l[s][3, 5]
10.divmod()求商和余数
>>> divmod(10,3)(3, 1)>>> divmod(10,2)(5, 0)>>>
1.abs
python内置方法
评论关闭