Question about Python embedding function all() with respect to logical operators.

Asked 2 years ago, Updated 2 years ago, 12 views

Hello, I'm Corinne.

The above all() function is a function that returns True if it is of an optional type, such as a list or dictionary.

I'm asking you because I don't know what the conditions for returning False are.

TypeError: 'int' object is not iterable

If you insert a non-iterable type, you will vomit the above typeerrr.

What is the condition of the notator?

python

2022-09-20 19:10

2 Answers

Condition to return false

0 or " (empty string)

a = [1,2,0,4,5]
print(all(a)) # False
b = "" 
print(all(b)) # False


2022-09-20 19:10

For example, if you have a list of students' gender,

 Starlight Class Student Sex = ["Other", "Other", "Other", "Other", "Other", "Other", "Other"]
Are you a starlight class student? = [Gender == "Men" for Gender in Starlight class]
If all:
  print ("All men!"
else:
  print ("There are girls, too!")

You can write it like this.


2022-09-20 19:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.