0
0
Pythonprogramming~15 mins

Membership operators (in, not in) in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Membership Operators (in, not in) in Python
📖 Scenario: You work at a library. You have a list of books currently available on the shelves. You want to check if certain books are in the library or not.
🎯 Goal: Build a small program that checks if some books are available in the library using membership operators in and not in.
📋 What You'll Learn
Create a list called library_books with exact book titles
Create a variable called check_book with a specific book title
Use in or not in to check if check_book is in library_books
Print the result as a sentence
💡 Why This Matters
🌍 Real World
Libraries, stores, and many apps need to check if an item is available in a collection before proceeding.
💼 Career
Understanding membership operators helps in filtering data, validating inputs, and controlling program flow in many programming jobs.
Progress0 / 4 steps
1
Create the list of books
Create a list called library_books with these exact book titles: 'The Hobbit', '1984', 'Pride and Prejudice', 'To Kill a Mockingbird', and 'The Great Gatsby'.
Python
Need a hint?

Remember to use square brackets [] to create a list and separate items with commas.

2
Set the book to check
Create a variable called check_book and set it to the string '1984'.
Python
Need a hint?

Use simple assignment with the exact string '1984'.

3
Check if the book is in the library
Use an if statement with the membership operator in to check if check_book is in library_books. Inside the if, create a variable called message and set it to "The book is available in the library.". In the else part, set message to "The book is not available in the library.".
Python
Need a hint?

Use if check_book in library_books: to check membership.

4
Print the result message
Print the variable message to show if the book is available or not.
Python
Need a hint?

Use print(message) to show the result.