Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

When to use 'if not...' as opposed to just changing comparison operators.

I am having a brain fart. Logically, can you show some examples of when I would use the 'if not...' statement as opposed to just changing comparison operators?

For instance:

why would I use

if not a > b: print('statement')

as opposed to

if a < b: print('statement')

I understand all of the syntax and what it does but I'm trying to wrap my brain around its practical uses. I've tried google but I'm not getting good results. I know I'm missing something obvious, I know, I know. I'm having a brain fart. Can you give me the 'ah ha' moment and hit me with a few practical examples?

1 Answer

Its just a matter of prefernce .Both litreally mean the same . NOT opreator acts the same like opposite. You can directly use the the less than operator ,OR you can choose to use to use the OPPOSITE of greater ,Which again gives only the lesser operator results.However you use results will be the same.

Thanks for that. Much appreciated. My brain was hurting trying to discover a difference.