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

not operator, real world application?

What would be a real world example of using the not operator?

For example, let's say:

employees = ['Fred', 'Ben', 'Harry']

if 'Fred' in employees:
    print('he works here')

That makes complete sense to me, but I can't seem to wrap my head around the 'not' operator...? Help would be much appreciated.

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Well what if we had this scenario. What if Fred is an employee of the store in question but not a manager. Maybe there is only certain code that should run if the person is also a manager? Or you want to print an error about needing more privileges on the system for employees that are not managers?

Or even more simply: What if a manager has access to an address list for employees that includes a search function (maybe it's a really big company). And when the manager does a search it comes up with a "Not found" if the person is not in the employees list.

Just some ideas off the top of my head :smile:

Ah, I see. Yes, this clarifies it quite nicely. Thank you for the response.