Levelling up my Python Skills: The Magic of in and not in . When learning Python, one of the first truly useful tools you discover is Membership Operators. Today, I wrote out a simple but clear guide in my notebook to explain how they work! 👉 What are they? They are used to test whether a specific sequence or object is present within another. They return a simple Boolean: True or False. 1️⃣ The in operator: This operator returns True if a value is present in the sequence. * My Example: Checking if the item 'banana' exists in our 'basket' list. 2️⃣ The not in operator: This returns True if a value is not present in the sequence. It's often easier to read than a negated statement (e.g., not 'grape' in a basket). * My Example: Checking if 'grape' is missing from the list. 🔑 Pro Tip from my Notebook: You can use in and not in on: * Lists (for checking full items) * Strings (for checking partial matches!) * Sets, Dictionaries (keys), and more. Understanding these simple operators makes writing conditionals, such as if/else, incredibly intuitive. It’s like teaching your code to have a quick check! #PythonProgramming #PythonCode #CodeNewbie #Learner #ProgrammingBasics #PythonNotebook #DataStructures #CodeWithMe
Mastering Python's in and not in Operators
More Relevant Posts
-
Day 6 of my Python learning journey Today I tried solving a problem that looked easy at first, but understanding the logic took some time. Problem: Two Sum Given a list of numbers and a target value, find the indices of the two numbers that add up to the target. Example: nums = [4, 5, 1, 8] target = 9 Output: [0, 1] Because 4 + 5 = 9. Code I wrote: nums = [4, 5, 1, 8] target = 9 d = {} for i in range(len(nums)): num = nums[i] comp = target - num if comp in d: print("Indices:", d[comp], i) print("Values:", nums[d[comp]], nums[i]) break d[num] = i Problems I faced while coding this: At first I tried two nested loops, which worked but felt inefficient. I was confused about why we store numbers in a dictionary. The line d[num] = i also confused me because I didn’t understand why we save the index. It also took time to understand how comp = target - num helps find the pair. What I finally understood: Instead of checking every pair, we store numbers we have already seen in a dictionary. Then we check if the required number already exists. This reduces the time complexity from O(n²) to O(n). From tomorrow we will start something different. I’m planning to build a small Python project that will take about 1 week. Tomorrow I will share the project roadmap, and then we will start with Day 1 of the project. #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
📘 Python Learning Series – Day 10 🐍 (Final Day) Today marks the final day of my Python learning series! 🚀 In this last post, I explored Exception Handling in Python. 🔹 What is Exception Handling? Exception handling is used to handle errors in a program gracefully without stopping the execution. 🔹 Why is it important? ✔ Prevents program crashes ✔ Handles runtime errors smoothly ✔ Improves user experience ✔ Makes code more reliable 🔹 Basic Syntax try: result = 10 / 0 except ZeroDivisionError: print("Cannot divide by zero!") finally: print("Execution completed.") 🔹 Output Cannot divide by zero! Execution completed. 📌 Key Points ✔ "try" → Code that may cause error ✔ "except" → Handles the error ✔ "else" → Runs if no error occurs ✔ "finally" → Always executes --- 🎉 Series Completed! From basics to important concepts, this journey helped me: ✅ Build strong fundamentals ✅ Stay consistent ✅ Improve coding confidence Grateful for everyone who followed along 🙌 This is just the beginning — more projects & learning coming soon! 💻✨ #Python #PythonLearning #CodingJourney #LearnPython #Developers #100DaysOfCode
To view or add a comment, sign in
-
-
Most beginners learn lists first. But dictionaries are where Python gets really powerful. I spent Day 4 of my journey going deep on Python Dictionaries — and I finally understand why every real-world Python project uses them constantly. Here's what clicked for me today 👇 A dictionary is just a way to store data with a label attached to it. Instead of remembering "index 0 is the name, index 1 is the age" — you just say: person["name"] → "Alice" person["age"] → 22 Clean. Readable. Obvious. And once you add these methods — it becomes a proper data structure: ✅ .get() — access values safely without crashing your code ✅ .update() — merge two dictionaries in one line ✅ .items() — loop through key-value pairs like a pro ✅ .setdefault() — set a value only if the key doesn't already exist ✅ Dict Comprehension — build entire dictionaries in a single line ✅ Nested Dicts — store complex real-world data like a database I made the cheat sheet above so I never have to Google these again. Save it if you're learning Python — it covers everything in one place. 🔖 What do you use dictionaries for most in your projects? Drop it in the comments 👇 Follow for more Madhesh B #Python #LearnToCode #PythonDictionaries #CodeNewbie #ProgrammingForBeginners #TechLearning #Madhesh B
To view or add a comment, sign in
-
-
Day 11 of my Python learning journey Today I tried solving the Two Sum problem using the Two Pointer technique. Before this, I was only solving Two Sum using a dictionary. But today I learned another approach that works when the array is sorted. Problem: Two Sum (Two Pointer Approach) Given a sorted array and a target value, find two numbers whose sum equals the target. Example: nums = [1, 2, 4, 6, 10] target = 8 Output: [2, 6] Because 2 + 6 = 8. What is the Two Pointer technique? Two pointers means using two positions in the array: one pointer starts from the left side one pointer starts from the right side Then we move them based on the sum. How it works: • If the sum is too small, move the left pointer forward • If the sum is too large, move the right pointer backward • If the sum equals the target, we found the answer Code: nums = [1, 2, 4, 6, 10] target = 8 left = 0 right = len(nums) - 1 while left < right: s = nums[left] + nums[right] if s == target: print(nums[left], nums[right]) break elif s < target: left += 1 else: right -= 1 Problems I faced while coding this: At first I did not understand why the array needs to be sorted. I was confused about when to move the left pointer and when to move the right pointer. I also tried using this method on an unsorted array and it did not work. What I finally understood: The Two Pointer technique works well when the array is sorted because it lets us adjust the sum efficiently without checking every pair. This reduces the time complexity compared to nested loops. Question: Would this approach still work if the array was not sorted? #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
🚀 Python Learning I used to think functions were complicated… Turns out, I was just overthinking. 👨🍳 Think of this: When you order food in a restaurant, you don’t go inside the kitchen and cook it yourself. You just give an order → and the chef handles everything. 💡 That’s exactly how functions work in Python. Instead of writing the same steps again and again, you define them once… and just “call” them whenever needed. 🔹 Example: def greet(name): print("Hello", name) greet("Dhanush") greet("Ram") greet("John") 🔥 What changed for me: Before functions → messy, repetitive code After functions → clean, reusable logic ⚠️ Mistake I made: I used to write everything in one long block. That’s not coding. That’s just typing more and creating bugs. #Python #Coding #Functions #LearningJourney Frontlines EduTech (FLM) Sai Kumar Gouru
To view or add a comment, sign in
-
-
🚀 Python Basics to Advanced Learning Series – Day 12 Today’s session was focused on the Set data structure in Python. It helped me understand how to store and manage unique values efficiently. What I learned today: • What is a Set and how it works in Python • How to create a set using {} and set() function • How to create an empty set using set() (since {} creates a dictionary) • Understanding that sets store unique and unordered elements • Learning important built-in methods of sets: add() → to add a single element update() → to add multiple elements copy() → to create a duplicate set pop() → to remove a random element remove() → to remove a specific element (error if not found) discard() → to remove element without error • Understanding the difference between pop(), remove(), and discard() • Practiced examples to clearly understand how sets behave This session helped me understand how sets are useful when working with unique data and how different methods behave in real scenarios. I’m learning step by step as part of my Python Basics to Advanced Learning Journey at Global Quest Technologies, and I’m improving my concepts day by day. Excited to continue learning and building strong fundamentals 🚀 #Python #PythonProgramming #LearningJourney #Coding #DataStructures #Sets #ProblemSolving #SoftwareDevelopment #TechLearning #Developers #GlobalQuestTechnologies
To view or add a comment, sign in
-
-
I used to think Python was HARD… until I understood this ONE concept 🤯 "Libraries. Modules. Packages." Sounds confusing? Let me simplify it for you think of Python like a toolbox Instead of building everything from scratch… You can just import tools made by experts. Need calculations? → "math" Need random values? → "random" Need data analysis? → "pandas" 💡 One line of code can save HOURS of work: "import numpy as np" That’s not just coding… That’s working smart. And that’s how you grow FAST If you're learning Python, remember this:You don’t need to know everything…You just need to know what to import. #Python #Programming #CodingForBeginners #DataScience #LearnToCode #Developers #TechSkills #AI #CareerGrowth #DigitalSkills
To view or add a comment, sign in
-
-
The past few weeks of learning at AI-FORGE have been amazing. We started off from the very basics of Python programmming language. Through the help of our amazing tutor Solomon Promise Eityeme, the first week of learning was on python fundamentals which includes 1) Understanding Python syntax rules — indentation, comments, and statements 2) Creating variables and python naming convention 3) Understanding and working with the four basic data types in Python: int, float, str, bool 4) The use of string indexing, slicing, and other methods to manipulate text 5) Learning and applying arithmetic, comparison, and logical operators Also, an extensive teaching was done on data structures, where I learnt how to: 1) Create and manipulate lists, which are ordered and mutable collections 2) Work with tuples. Tuples are ordered, immutable collections 3) Use sets for storing unique values and performing set operations 4) Build and query dictionaries, which are key-value pairs for fast lookups 5) Choose the right data structure for a given problem, and also the method of combining multiple data structures to solve real-world problems. I had a lot of exercises to practice with and showcase what I have learnt over the first few weeks of learning the Python basics. At the end of the week, we were given real world problem to develop a solution for. For this, I created a contact manager by using dictionary to store the contacts of six individuals. It was able to add new contact, print all contact names, find contacts with specific tags, amongst other functions. Here is a snippet of the code, and I published the full Jupyter workbook on GitHub which can be accessed via this link: https://lnkd.in/eScdckgy #AI-FORGE #Python #AI #ML
To view or add a comment, sign in
-
-
Everyone wants to learn Python first. Because in Python you can write something like: print("Hello World") One line. Done. You feel like a programmer already. But try writing the same thing in C. Suddenly you see things like: #include <stdio.h> int main() { printf("Hello World"); return 0; } And many students ask: "Why so much extra code?" But that “extra code” is where the real learning lives. C quietly teaches you things that high-level languages hide: • How a program actually starts (main function) • How libraries are included (#include) • How memory is managed • How the system talks to the hardware Python makes you productive fast. C makes you understand what’s actually happening. And in technology, speed without understanding is temporary. Every modern tool we use today— operating systems, databases, interpreters, compilers— has its roots somewhere in C. So when someone says “C is outdated”, it’s like saying “foundations are outdated because buildings look modern now.” You may not write C every day. But if you understand C, you start seeing the invisible machinery behind every program you run. Teaching what they taught me🔥
To view or add a comment, sign in
-
🐍 Day 2 of Learning Python Continuing my Python learning journey and today’s focus was on understanding how Python actually executes code behind the scenes, along with practicing some fundamental concepts. 🔎 What I explored today: ⚙️ How Python Executes Code I learned that Python does not directly run the code we write. Instead, the Python interpreter first converts the source code into Bytecode, which is then executed by the Python Virtual Machine (PVM). Understanding this process helped me see how Python translates human-readable instructions into something a computer can execute. 🧠 Variables in Python After that, I practiced working with variables, which are used to store data in memory. Python makes this simple since we don’t need to explicitly declare the data type — the interpreter handles it dynamically. 💻 Taking User Input To practice further, I wrote a small program where the user enters their name and age, and the program prints a formatted message. Example concept used: input() for user input. int() to convert age into an integer. f-strings for clean and readable output formatting. This small exercise helped me understand data types, variable assignment, and interaction with users through the terminal. Every day I’m trying to strengthen the fundamentals because strong basics make advanced topics like automation, AI, and machine learning easier to approach later. Looking forward to exploring more Python concepts tomorrow. 🚀 #Python #PythonProgramming #LearningPython #CodingJourney #100DaysOfCode #SoftwareDevelopment #ProgrammingBasics #TechLearning #Developers #FutureEngineer #LearnInPublic #PythonBeginner #SDE
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development