标签:__ 内置 PythonProject python 方法 test print True
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.py
2
e
3
4
w
6
Process finished with exit code 0
5.all()所有的为true,才返回true。空的列表返回true
print(all([1, 2, 0])) # 列表中的0是False,所以返回False
print(all([1, 2, 5])) # 列表中的所有值都是True,所以返回True
print(all([])) # 空的列表,all()返回true
print(help(all))
E:\PythonProject\python-test\venvP3\Scripts\python.exe E:/PythonProject/python-test/BasicGrammer/test.py
False
True
True
Help 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.
None
Process finished with exit code 0
6.any()任意一个为true就返回true。空的列表返回false
any()列表中的任意一个为True,就返回True
print(any([1, 2, 0]))
print(any([1, 2, 5])) # 列表中的任意一个是True,就返回True
print(any([])) # 空的列表,any()返回false
print(help(any))
E:\PythonProject\python-test\venvP3\Scripts\python.exe E:/PythonProject/python-test/BasicGrammer/test.py
True
True
False
Help 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.
None
Process 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.py
0x10
Process 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
标签:__,内置,PythonProject,python,方法,test,print,True
来源: https://blog.51cto.com/10983441/2388232
本站声明:
1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。