all()
checks if all items in an array are True, then returns a boolean. To check if a number is less than zero in the list, you can do: all([i>=0 for i in [-1,-2,-3,3]])
I would just do
if max(test_3) <= 0:
print("all negative")
else:
print("there is a positive")
This seems more explicit to me that you want the maximum value to be 0 or less
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.