标签:信息 bool 切片 process python not make 打印 list
1.abs取绝对值>>> abs(9.8)
9.8
>>> abs(-9.8)
9.8
>>> dict({"key":"value"})
{‘key‘: ‘value‘}
>>> 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 --
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
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
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
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
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
>>> 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]
>>> divmod(10,3)
(3, 1)
>>> divmod(10,2)
(5, 0)
>>>
标签:信息 bool 切片 process python not make 打印 list
原文地址:https://blog.51cto.com/10983441/2388232