LoginSignup
1
3

More than 3 years have passed since last update.

[python] boolのリストの中身が全部Trueか、あるいはTrueが含まれるかの判定

Last updated at Posted at 2021-04-16
  1. 全部Trueか(Falseが含まれるか)どうかはall()で確認できる。

    print(all([True, True, True]))
    # True
    
    print(all([True, False, True]))
    # False
    
  2. Trueが含まれるか(全部Falseか)どうかはany()で確認できる。

    print(any([True, False, False]))
    # True
    
    print(any([False, False, False]))
    # False
    

まとめると、以下。

<bool> 全部<>か <>が含まれるか
True all(hoge) any(hoge)
False not any(hoge) not all(hoge)

※hogeはイテラブルな何か。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3