🚀 Understanding super() in Python (with a simple clarity boost!) Many learners get confused about one question: 👉 “If we are using parent methods and variables, why don’t we always use super()?” Let’s clear this up 👇 🔷 Key Idea You use super() only when you override a method and still want to use the parent version. 🔷 Case 1: No Overriding → No super() needed class Vehicle: def show(self): print("Vehicle details") class Car(Vehicle): pass car = Car() car.show() ✅ Output: Vehicle details 👉 Python automatically checks the parent class if the method is not found in the child. 👉 This is inheritance working by default. 🔷 Case 2: Overriding → super() becomes useful class Car(Vehicle): def show(self): super().show() print("This is a car") ✅ Output: Vehicle details This is a car 👉 Now we are extending the parent method, not replacing it. 🔷 Case 3: Overriding __init__ → super() is important class Car(Vehicle): def __init__(self): super().__init__() 👉 Without super(), parent variables won’t be initialized ❌ 🔷 Simple Rule to Remember ✔ No override → Python uses parent automatically ✔ Override → Parent is hidden ✔ Use super() → To bring parent behavior back 💡 One-line takeaway super() is not for inheritance — it’s for accessing the parent implementation when you override it. This small concept makes a big difference when teaching or writing clean OOP code in Python 💻✨ #Python #OOP #Coding #Programming #Developers #Learning #TechEducation
Understanding super() in Python for Inheritance
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
-
-
Teach With Tech: Understanding range() in Python 🧠💡 Let’s explore a simple yet powerful concept every Python beginner should know — range(). If you’ve ever wondered how programmers make things repeat without writing the same code over and over, this is one of the go-to tools. 🔹 What is range()? range() is a built-in Python function that generates a sequence of numbers. Think of it as a smart counter that does the counting for you. 🔹 Basic Syntax range(start, stop, step) start → where counting begins stop → where it ends (this number is NOT included) step → how much it increases each time 🔹 Simple Examples ✅ Example 1: for i in range(5): print(i) Output: 0 1 2 3 4 👉 Starts from 0 by default and stops before 5. ✅ Example 2: for i in range(2, 7): print(i) Output: 2 3 4 5 6 👉 Starts from 2 and stops before 7. ✅ Example 3: for i in range(1, 10, 2): print(i) Output: 1 3 5 7 9 👉 Counts with a step of 2. 🔹 Why it matters range() helps you: - Automate repetition - Keep code clean and concise - Control loops with ease 🔹 Beginner Tip If your loop seems to “miss” the last number you expected… don’t worry 😄 👉 range() always stops BEFORE the final number. Learning small concepts like this may seem simple, but they’re the building blocks of real-world programming. Keep learning. Keep creating. 🚀 @TechCrush.pro #RisewithTechCrush #Tech4Africans #LearningwithTechCrush
To view or add a comment, sign in
-
-
Today was one of those Python lessons that felt less like learning code and more like learning how to read its warnings properly. 🐍 Day 15 of my #30DaysOfPython journey was all about errors, and honestly, this topic matters because every developer runs into them. When Python code fails, it gives feedback that tells us where the issue is and what kind of problem it is. Learning to understand those messages makes debugging a lot faster. Today I went through the common ones: 1. SyntaxError — when the code is written incorrectly 2. NameError — when a variable has not been defined 3. IndexError — when an index goes out of range 4. ModuleNotFoundError — when a module cannot be found 5. AttributeError — when an attribute does not exist 6. KeyError — when the wrong key is used in a dictionary 7. TypeError — when an operation is applied to the wrong data type 8. ImportError — when something is imported incorrectly 9. ValueError — when the value is valid in type, but not in meaning 10. ZeroDivisionError — when a number is divided by zero What stood out to me today was how errors are not just problems — they are clues. Once you stop panicking and start reading them properly, debugging becomes a lot less intimidating. One more day, one more topic, one more step toward writing code with less guessing and more understanding. Which error has annoyed you the most while coding so far? #Python #LearnPython #CodingJourney #30DaysOfPython #Programming #DeveloperJourney
To view or add a comment, sign in
-
Day 9 of learning Python Today was all about diving deep into the "What if?" of programming. I spent the day exploring how to make my code more resilient and user-friendly by mastering Bugs and Exceptions in Python. 🐍💻 Here’s a breakdown of the key takeaways from my learning documentary today: 1. The Anatomy of a Mistake: Bugs vs. Exceptions Not all errors are created equal. I learned to distinguish between the two major categories: Bugs: These are the logic flaws. The program might run to the end, but it gives the wrong answer—like a calculator saying 2+2=5. Exceptions: These are the "show-stoppers." They happen during execution and will crash the program immediately if they aren't handled. 2. Identifying the Culprits I spent time matching specific error types to their causes. Recognizing these early is a superpower for any developer: SyntaxError: You missed a colon or a bracket. IndexError: You tried to access the 10th item in a list that only has 5. ValueError: You tried to turn the word "Apple" into an integer. NameError: You called a variable that hasn't been defined yet. 3. The Power of try/except The most exciting part of today was learning how to predict the unpredictable. Instead of letting a program crash when an error occurs, I can use a try/except block. The try block tests a piece of code. The except block provides a "safety net" to catch the error and keep the program running smoothly. 🛡️ The big lesson? A good developer doesn't just write code that works; they write code that knows what to do when things go wrong. Onwards to the next challenge! 📈 #Python #CodingJourney #SoftwareDevelopment #LearningToCode #TechSkills #ErrorHandling #PythonProgramming #Sololearn
To view or add a comment, sign in
-
-
Most beginners memorize Python… but never actually think like a programmer. Day 9 of my Python journey changed that. ⚡ So far, I’ve been building consistency—showing up daily, learning step by step. But today’s deep dive into dictionaries & sets flipped a switch in my brain. Here’s what clicked: 1️⃣ Dictionaries = Real-world thinking Stop seeing them as syntax. Start seeing them as relationships. Keys → Questions Values → Answers 2️⃣ Methods aren’t “extra” — they’re power tools🔧 `.get()` saved me from errors `.keys()` & `.values()` helped me think in structure, not chaos 3️⃣ Sets = Clean data, fast decisions No duplicates. No noise. Just clarity. That’s how real systems think. 💭 The challenge? At first, everything felt confusing—too many methods, too many rules. But instead of jumping ahead, I slowed down… practiced… broke things… fixed them. That’s when learning turned into understanding. 🚀 If you're learning to code, remember: Don’t rush to finish Python. Master how it thinks. 👇 Drop a comment: Are you still memorizing… or starting to understand? Let’s grow together. 💡
To view or add a comment, sign in
-
-
🐍 Why One Version Works… and the Other Doesn’t (Python Classes Explained) Ever faced this situation while learning Python? 👇 One version of your class throws an error ❌ Another version works perfectly ✅ Let’s understand why 👇 🔴 First Case (Error) class Dog: def __init__(self, name, breed): self.name = name self.breed = breed john = Dog(name="Husk") 💥 This gives an error because: The constructor __init__ expects 2 arguments → name and breed But you only provided 1 argument 👉 Python says: “Hey, I’m missing breed!” 🟢 Second Case (Works Fine) class Dog: def __init__(self, name, breed="None"): self.name = name self.breed = breed john = Dog(name="Husk") ✅ This works because: breed now has a default value If you don’t pass it, Python automatically uses "None" 💡 Key Concept: Default Parameters When you assign a default value: The argument becomes optional Your code becomes more flexible 🎯 Simple Rule to Remember No default value → argument is required Default value given → argument is optional 🚀 Small concepts like these build strong programming foundations. Keep experimenting and breaking things—that’s how you really learn! #Python #Coding #Programming #Beginners #LearnToCode #SoftwareDevelopment
To view or add a comment, sign in
-
🚀 Python Learning Journey – Day 28 (Continue) Today I continued exploring key OOP concepts in Python: --- 🔹 Method Overriding When a child class provides its own implementation of a parent class method. class A: def show(self): print("Parent class") class B(A): def show(self): print("Child class") obj = B() obj.show() # Output: Child class --- 🔹 "__str__()" Method Used to return a readable string representation of an object. class Student: def __str__(self): return "Student Object" s = Student() print(s) # Output: Student Object --- 🔹 Abstract Class & Abstract Method Abstract classes are created using "ABC" and contain abstract methods that must be implemented. from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass class Square(Shape): def area(self): return "Area calculated" obj = Square() print(obj.area()) --- 💡 Key Takeaway: Method overriding helps in customization, "__str__()" improves readability, and abstract classes enforce structure in programs. 📈 Step by step learning and building strong Python fundamentals! #Python #OOP #LearningJourney #100DaysOfCode #PythonDeveloper
To view or add a comment, sign in
-
-
Most people start learning Python… but quit halfway. Python isn’t difficult — the real problem is unstructured learning. I came across a structured 15-day Python roadmap and it perfectly explains why most learners struggle. 💡 It’s not about doing more — it’s about doing it right. Instead of jumping between random tutorials, this roadmap focuses on: Strong fundamentals (variables, loops, functions — Day 2–4) Consistent problem-solving practice every single day (seen across all pages) Real-world concepts like file handling, OOP, and data analysis (Day 8–12) Even advanced topics like Machine Learning basics (Day 15) 👉 That’s how learning actually sticks. Here’s what changed for me: I stopped rushing. I started building my own notes + solving daily problems. And suddenly… things started making sense. 📌 Truth is: You don’t need 10 courses. You need one structured path + consistency. From automation to AI, Python opens doors everywhere — but only if you stay long enough to master it. 🚀 If you're starting Python: Focus on clarity Practice daily Build small projects Stay consistent Because in the long run… consistency beats intensity. 💬 Are you currently learning Python? Drop “PYTHON” below — let’s grow together! #Python #Coding #Programming #LearnToCode #PythonNotes #Developers #Tech #100DaysOfCode #CareerGrowth #SoftwareDevelopment
To view or add a comment, sign in
-
print() and input() in Python — Two Functions. The Entire Conversation. Before loops, before functions, before data structures — any interactive program needs to solve two basic problems: how to send information to the user, and how to receive information from them. In Python, that’s where print() and input() come in. They’re the first two built-in functions the Helsinki MOOC introduces, and the reason is straightforward: without them, your program runs silently and alone. Nothing goes out, nothing comes in. print() handles output. It takes whatever you pass it and displays it in the terminal. That can be a string, a number, a variable, or a combination of all three: print("Current temperature:", temperature, "°C") Simple. But the moment you add it to your code, your program starts communicating. input() handles the other direction. It pauses the program, displays a message to the user, and waits. Whatever the user types is returned as a string that your program can then work with: city = input("Enter your city: ") One detail worth noting early: input() always returns a string, regardless of what the user types. If you ask for a number and plan to do arithmetic with it, you need to convert it explicitly. That’s not a flaw — it’s Python being precise about types, which is a habit worth developing from the start. Together, these two functions establish a pattern that scales across the entire language: programs receive data, process it, and return a result. print() and input() are just that pattern in its most direct form. Everything more complex is built on top of this. #Python #PythonMOOC2026 #BackendDevelopment #SoftwareEngineering #LearningInPublic #UniversityOfHelsinki
To view or add a comment, sign in
-
-
Day 18 of my Python learning journey Today I tried another good problem based on the Two Pointer technique. Problem: Merge Sorted Array Given two sorted arrays, merge them into one sorted array. Example: arr1 = [1, 3, 5] arr2 = [2, 4, 6] Output: [1, 2, 3, 4, 5, 6] What I understood: Since both arrays are already sorted, we do not need to sort again. We can compare elements from both arrays and place the smaller one first. Better approach (Two Pointer): One pointer for arr1 One pointer for arr2 Compare both values Add the smaller value to the result Code I wrote: arr1 = [1, 3, 5] arr2 = [2, 4, 6] i = 0 j = 0 result = [] while i < len(arr1) and j < len(arr2): if arr1[i] < arr2[j]: result.append(arr1[i]) i += 1 else: result.append(arr2[j]) j += 1 while i < len(arr1): result.append(arr1[i]) i += 1 while j < len(arr2): result.append(arr2[j]) j += 1 print(result) Problems I faced while coding this: At first I thought I had to combine both arrays and then sort them. I was confused about why two pointers are enough. I also forgot to handle the remaining elements after one array finishes. What I finally understood: Because both arrays are sorted, we can merge them in one pass. This saves extra sorting work and makes the solution efficient. Time and Space Complexity: Time Complexity: O(n + m) Space Complexity: O(n + m) Question: What will be the output for: arr1 = [1, 2, 7] arr2 = [3, 4] Today’s realization: Sometimes the best solution is not creating something new, but combining what is already ordered. #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
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