Python 的 all(~)
方法返回一個布爾值,指示輸入可迭代的所有元素是否為 true。
參數
1. iterable
| iterable
用於檢查元素是否為 true 的迭代。
返回值
一個布爾值,指示輸入可迭代的所有元素是否均為 true。另外,如果迭代器為空,則返回True
。
例子
檢查列表 x
中的所有元素是否為 true:
x = ['cake', 'cookie', 'cupcake', ['pudding','tea']]
all(x)
True
檢查字典 y
中的所有元素是否為 true:
y = {0:'zero', 1:'one', 2:'two'}
all(y)
False
由於 0
為 false,因此字典中並非所有元素都為 true,因此返回 False
。
檢查集合 z
中的所有元素是否為 true:
z = {}
all(z)
True
由於集合為空,因此返回True
。
相關用法
- Python NumPy all方法用法及代碼示例
- Python all用法及代碼示例
- Python all()用法及代碼示例
- Python NumPy allclose方法用法及代碼示例
- Python arcgis.gis._impl._profile.ProfileManager.save_as用法及代碼示例
- Python arcgis.raster.functions.ccdc_analysis用法及代碼示例
- Python arcgis.geometry.functions.trim_extend用法及代碼示例
- Python arcgis.raster.analytics.sample用法及代碼示例
- Python arcgis.features.analysis.derive_new_locations用法及代碼示例
- Python arcgis.features.analyze_patterns.calculate_density用法及代碼示例
- Python arcgis.geometry.Geometry.label_point用法及代碼示例
- Python ast.MatchClass用法及代碼示例
- Python arcgis.plan_routes用法及代碼示例
- Python arcgis.mapping.forms.FormInfo用法及代碼示例
- Python arcgis.gis.UserManager.get用法及代碼示例
- Python arcgis.raster.ImageryLayerCacheManager.update_tiles用法及代碼示例
- Python arcgis.geometry.Geometry.true_centroid用法及代碼示例
- Python arcgis.gis.User.generate_direct_access_url用法及代碼示例
- Python arcgis.gis.GroupMigrationManager.create用法及代碼示例
- Python arcgis.geometry.Geometry.hull_rectangle用法及代碼示例
- Python arcgis.features.analysis.summarize_within用法及代碼示例
- Python arcgis.geometry.filters.intersects用法及代碼示例
- Python arcgis.geometry.functions.project用法及代碼示例
- Python abc.ABCMeta用法及代碼示例
- Python arcgis.raster.functions.percentile用法及代碼示例
注:本文由純淨天空篩選整理自Arthur Yanagisawa大神的英文原創作品 Python | all method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。