参数 整数或复数
返回一个数的绝对值。实参可以是整数或浮点数。如果实参是一个复数,返回它的模。
a = -1
print(abs(a)) # 1
a = 0.23-8.33j
print(abs(a)) # 8.33317466515613
参数 可迭代对象 list dict
Return True if bool(x) is True for all values x in the iterable.
If the iterable is empty, return True.
如果 iterable 的所有元素为真(或迭代器为空),返回 True 。
空
all([]) # True
all({}) # True
all(()) # True
list,tuple,set
all([1,2,3,4]) # True
all([0,None,False,‘‘,(),{},[]] # False
dict
all({‘das‘:0,‘asd‘:None,‘adsa‘:False,‘asda‘:‘‘,‘adsasdad‘:{}}) # True
all({‘‘:‘dasd‘,False:‘dsad‘,None:‘asd‘,0:‘dasd‘}) # False
def all(iterable):
for element in iterable:
if not element:
return False
return True
# 循环一个空的迭代其对象不会报错
Return True if bool(x) is True for any x in the iterable. If the iterable is empty, return False. 如果 iterable 的任一元素为真则返回 True。如果迭代器为空,返回 False。
空
all([]) # False
all({}) # False
all(()) # False
list,tuple,set
all([1,2,3,4]) # True
all([0,None,False,‘‘,(),{},[]]) # False
dict
all({‘das‘:0,‘asd‘:None,‘adsa‘:False,‘asda‘:‘‘,‘adsasdad‘:{}}) # True
all({‘‘:‘dasd‘,False:‘dsad‘,None:‘asd‘,0:‘dasd‘}) # False
def any(iterable):
for element in iterable:
if element:
return False
return True
原文:https://www.cnblogs.com/yuyafeng/p/10964993.html