Skip to content

Latest commit

 

History

History
56 lines (44 loc) · 2.09 KB

File metadata and controls

56 lines (44 loc) · 2.09 KB
title Python 組み込み関数 all() - Python チートシート
description イテラブルの全要素が真である場合に True を返す(イテラブルが空の場合も True)。
Python all() ビルトイン関数 Python 3 ドキュメントより イテラブルのすべての要素が真である場合(またはイテラブルが空の場合)に True を返します。

Introduction

Python の all() 関数は、イテラブル内のすべての要素が True であるかどうかをチェックするビルトイン関数です。すべての要素が真と評価される場合、またはイテラブルが空の場合に True を返します。これは、リスト内のすべての数値が正であるか、フォーム内のすべての必須フィールドが入力されているかなど、コレクション全体の状態を検証する場合に役立ちます。

Examples

# すべての値が真値 (truthy)
all([1, 2, 3])

# 偽値 (falsy) (0) を含む
all([1, 0, 3])

# 偽値 (空文字列) を含む
all(['a', '', 'c'])

# 空のイテラブルは True と見なされる
all([])
True
False
False
True

Relevant links

  • Cheatsheet: Control Flow
  • Cheatsheet: Comprehensions
  • Blog: Python Data Types
  • any()
  • bool()
  • list()
  • tuple()
  • set()
  • dict()