Python - detecting values in a list -


this question has answer here:

how detect if value held in list negative, need find out if there value negative, far have this:

if list[range(list)] < 0 

but surely detect if values in list negative.how go doing this?

also, how able detect if value in list not integer, example floating point number, or character

thanks

you can use any function, this

if any(item < 0 item in my_list): 

for example,

print any(item < 0 item in [0, 1, 2]) # false print any(item < 0 item in [0, 1, -2]) # true 

we use generator expression in any function. returns true, if of item lesser 0.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -