💡 𝗪𝗵𝘆 𝗱𝗼𝗲𝘀 𝗣𝘆𝘁𝗵𝗼𝗻 𝗸𝗲𝗲𝗽 𝘁𝗮𝗹𝗸𝗶𝗻𝗴 𝘁𝗼 𝗶𝘁𝘀𝗲𝗹𝗳? 🐍🤔 If you've ever looked at a Python class, you’ve definitely seen it… 👉 that mysterious first parameter: `self` At first, it feels unnecessary. Like… why is Python repeating itself? --- 🏠 Think of a class as a *house blueprint* The blueprint says: "A house has a front door." But the blueprint doesn’t *have* a door. When you build 100 houses, each house needs to know: 👉 which door belongs to *it* --- 🏷️ That’s exactly what `self` does It’s like an **address tag** for each object. When you write: `self.name = name` You’re telling Python: 👉 “Store this value in THIS specific object.” --- 🙄 But why do we have to write it every time? Because Python follows: 👉 *Explicit is better than implicit* It doesn’t guess. It makes you be clear. --- 🍲 Imagine this: A waiter walks into a crowded restaurant and shouts: “HERE IS YOUR SOUP!” No table number. No context. Chaos. That’s your code **without `self`** ❌ --- ✅ With `self`: • Every object knows its own data • No confusion • Clean, readable code --- 🚀 Pro tip: You can name it anything (`this`, `me`, even `ketchup`) But don’t. 👉 Stick to `self` — your teammates will thank you --- 🙏 Special thanks to my mentor Sai Kumar Gouru 🏫 Learning with Frontlines EduTech (FLM) --- 💬 What confused you the most when learning OOP? #Python #OOP #Programming #CodingForBeginners #SoftwareEngineering #PythonTips #LearnToCode
Understanding Python's self parameter in object-oriented programming
More Relevant Posts
-
I think dictionaries might be the first Python topic that actually feels like organizing real life. 🐍 Day 08 of my #30DaysOfPython journey was all about dictionaries, and this one felt especially useful because it is basically how Python stores meaningful information. A dictionary is an unordered, mutable key-value data type. You use a key to reach a value — simple, but powerful. Today I explored: 1. Creating dictionaries with dict() built-in function and {} 2. Storing different kinds of values like strings, numbers, lists, tuples, sets, and even another dictionary 3. Checking length with len() 4. Accessing values using key name in [] or get() method 5. Adding and modifying key-value pairs 6. Checking whether a key exists using in operator 7. Removing items with pop(key), popitem() (removes the last item), and del 8. Converting dictionary items with items() which returns a dict_item object that contains key-value pairs as tuples 9. Clearing a dictionary with clear() 10. Copying with copy() and avoids mutation 11. Getting all keys with keys() and values with values(). These will return views - dict_keys() and dict_values() What stood out to me today was how dictionaries make data feel searchable instead of just stored. That key-value structure makes them one of the most practical tools in Python when working with real information. One more day, one more topic, one more step toward thinking in Python instead of just reading Python. When did dictionaries finally stop feeling confusing for you — or are they still one of those topics that need a second look? Github Link - https://lnkd.in/ewzDyNyw #Python #LearnPython #CodingJourney #30DaysOfPython #Programming #DeveloperJourney
To view or add a comment, sign in
-
Hello there and welcome to this new section called: 'Learning Python with me'. Today, I will bring you one of the most basic commands, and we will create a name generator using Python. I am very excited to start this project and have you coming along with me! Scenario: We have a friend who has a beer company. He has everything: the product, the manufacturing, and the investment. But he is missing one single thing—the name of the company. He is struggling to think about it and asked us for help to create a name for him. We will use Python to generate two questions and combine them to create his beer company name! What will we use in Python: As you can see in the video, I am starting by leaving notes in Python. However, these notes cannot be left by themselves; they need to be preceded by a "#" symbol, which makes Python understand we are leaving comments instead of writing code. Variables: Variables are containers used to store data values. You create one by giving it a name and assigning a value using the "=" operator. Strings: Strings are sequences of text. In Python, they must be wrapped in either single quotes (' ') or double quotes (" "). Input: input() is a way to get information from the user. It allows the program to 'pause' and wait for you to type something into the console. So, as you can see, we are combining strings and inputs in the video. Why am I mentioning variables if I did not use them in the code? Because variables and strings tend to go together, so I could have used a variable to store and print the strings, something like this: result = ("The beer company name is: " + input("What is your favorite color?: ") + input("What is your favorite animal?: ")) print(result) This works exactly like the example in the video (you can test it). It's just that I put the print statement directly on the same line. As programmers, we want to save as much work as possible, so we keep everything clean and easy to read. I hope you enjoy it!" #Python #PythonProject #personalproject #DataScience #SideProject.
To view or add a comment, sign in
-
🚀 Python Essentials: Range, For Loop, Enumerate & List Comprehension 💡"Write cleaner, smarter, and more Pythonic code." 🔢 range Definition: Generates a sequence of numbers. Syntax: range(start, stop, step) Example: for i in range(1, 6): print(i) # 1 to 5 🔄 for loop Definition: Iterates over a sequence. Syntax: for variable in sequence: Example: fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit) 🏷️ enumerate Definition: Adds a counter to an iterable. Syntax: enumerate(iterable, start=0) Example: for index, fruit in enumerate(fruits, start=1): print(index, fruit) ⚡ List Comprehension Definition: Concise way to build lists. Syntax: [expression for item in iterable if condition] Example: squares = [x**2 for x in range(1, 6)] print(squares) # [1, 4, 9, 16, 25] ✨ These four tools are the backbone of writing efficient loops and data transformations in Python. Master them, and your code will be cleaner, faster, and more elegant. "Python isn’t just about writing code—it’s about writing it beautifully.” 🔖#PythonProgramming #LearningJourney #CodingInPublic #EntriLearning #CodeNewbie #Python #ProgrammingBasics #DataAnalytics #CareerGrowth #LinkedInLearning #LearnWithMe #BeginnerFriendly #AnalyticsInAction #CodeSmart
To view or add a comment, sign in
-
-
Day 2 of #30DaysOfPython ✅ Today's lesson: Python doesn't care how you label things — until it does. I spent today learning variables and data types. Sounds basic. It is basic. But here's what I didn't expect — Python's dynamic typing actually confused me at first. In theory, I knew that x = 5 and x = "five" are both valid. In practice, I accidentally added a string to an integer and got a TypeError I didn't understand for 10 whole minutes. The bug? I was reading user input and forgetting that input() always returns a string. So my "sum" was just two numbers glued together like "510" instead of 15. 🤦 What clicked today: • int, float, str, bool — the four I'll use constantly • type() is your best friend when debugging • Python is forgiving… until you mix types Lesson of the day: Read your error messages. The answer is usually right there. Resources I used: Python.org official docs + a great freeCodeCamp YouTube video. Day 2 done. The bugs are starting early — right on schedule. 😅 👇 What's the sneakiest beginner Python bug you ever ran into? Tell me so I can be prepared! #Python #30DaysOfPython #DataTypes #CodingJourney #TechLearning
To view or add a comment, sign in
-
-
🚀 Python Series – Day 16: Modules & Packages (Write Clean & Reusable Code!) Yesterday, we learned Exception Handling ⚠️ Today, let’s learn how to avoid writing messy code and reuse it like a pro 📦 🧠 First, Think Like This 👉 Imagine you write 100 lines of code in one file 😵 👉 It becomes confusing, hard to manage, and difficult to reuse 💡 Solution? → Modules & Packages 🔹 What is a Module? 👉 A module = one Python file (.py) 👉 It contains functions, variables, or classes 📌 In simple words: “Module = Separate file for better organization” 💻 Example (Real Understanding) 👉 Create a file: my_module.py def greet(name): return f"Hello {name}" 👉 Now use it in another file: import my_module print(my_module.greet("Mustaqeem")) ⚡ Built-in Module Example Python already gives ready modules: import math print(math.sqrt(25)) 👉 Output → 5.0 🔹 What is a Package? 👉 A package = folder of multiple modules 📌 In simple words: “Package = Collection of related modules” 📦 Example Structure my_package/ math_utils.py string_utils.py 👉 This keeps your project clean and structured 🎯 Why This is Important? ✔️ Avoids messy code ✔️ Makes projects easy to manage ✔️ Helps reuse code again & again ✔️ Used in real-world projects & companies ⚠️ Pro Tip (Very Important) 👉 Don’t write everything in one file ❌ 👉 Break your code into modules ✅ 🔥 One-Line Summary 👉 Module = File 👉 Package = Folder of files 📌 Tomorrow: OOP in Python (Classes & Objects – Game Changer!) Follow me to learn Python from basics to advanced 🚀 #Python #Coding #Programming #DataScience #LearnPython #100DaysOfCode #Tech #MustaqeemSiddiqui
To view or add a comment, sign in
-
-
Today's topic: recursion. A function that calls itself. Sounds simple, right? Here are two ways to add up a list of numbers: Without recursion — honest, reliable, easy to follow: python def suma(lista): suma = 0 for i in range(0, len(lista)): suma = suma + lista[i] return suma print(suma([6,3,4,2,10])) # 25 With recursion — elegant, almost poetic... and a little terrifying: python def suma(lista): if len(lista) == 1: return lista[0] else: return lista[0] + suma(lista[1:]) print(suma([6,3,4,2,10])) # 25 Same result. Two completely different roads to get there. The recursive version looks more "pro" — but if you forget to define when it stops, the function calls itself forever. Literally. Forever. 💀 So yes, it's getting challenging. And yes, recursion feels more elegant to write. But I'm not ready to fully trust something that could loop into oblivion if I blink wrong. Lesson of the day: simple is not the same as bad. And documenting the moments that confuse you? That's part of learning too. #Python #LearningToCode #DaysOfCode #PythonProgramming #CodingJourney #Recursion #BeginnerCoder #TechLearning #CodeNewbie #LinkedInLearning
To view or add a comment, sign in
-
-
🐍 Python List Operations – The Only Cheat Sheet You'll Need Master lists with these 25+ essential operations: 🔍 Accessing & Finding • list[i] → Get single item by index • list[start:end] → Get multiple items (slicing) • a, b, c = list → Unpack all items into variables • list.index(x) → Find position of first item with value x • x in list → Check if value x exists (True/False) 📊 Analyzing & Counting • len(list) → Total number of items • list.count(x) → Count how many times value x appears • max(list) / min(list) → Find highest/lowest values ✏️ Modifying Lists • list.append(x) → Add item x to the end • list.insert(i, x) → Insert item x at index i • list.extend(other_list) → Add items from another list • list[index] = new_value → Change item at specific index 🗑️ Removing Items • list.pop(i) → Remove and return item at index i (default last) • list.remove(x) → Remove first occurrence of value x • list.clear() → Remove all items 🔄 Sorting & Copying • list.sort() → Sort list in place (ascending) • list.reverse() → Flip order in place • new_list = sorted(list) → Get sorted copy • copy_list = list.copy() → Create a shallow copy ⚙️ Iteration & Processing • enumerate(list) → Iterate with index and value • [fn(x) for x in list if condition] → List comprehension (filter + transform in one line) • zip(list_a, list_b) → Pair items from two lists 💡 Pro tip: List comprehension is the most elegant Python feature. Master it and you'll write cleaner, faster code. #Python #PythonLists #CodingCheatSheet #DataStructures #LearnPython
To view or add a comment, sign in
-
-
Day 12/365: Checking If a List Is a Palindrome in Python 🔁 Today I solved a classic problem in Python: checking whether a list is a palindrome or not — using the two‑pointer technique with a for-else loop. 🔍 How this works step by step: I start with a list l that has elements arranged symmetrically. To check if it’s a palindrome, I compare elements from both ends: l[0] with l[-1], l[1] with l[-2], and so on. I only need to go till the middle of the list: range(len(l)//2) Inside the loop: If any pair doesn’t match, I print "list is not palindrome" and use break to exit the loop early. The interesting part is the for-else: The else block runs only if the loop finishes without hitting a break. That means all pairs matched, so I print "list is palindrome". 💡 What I learned: How to use the two‑pointer technique to compare elements from start and end efficiently. How Python’s for-else works — the else is tied to the loop, not the if. Why we only need to iterate till the middle of the list for palindrome checking. How the same logic can be reused for: checking if a string is a palindrome, validating symmetric data in lists and arrays. Day 12 done ✅ 353 more to go. If you have ideas like: checking palindromes while ignoring cases/spaces in strings, handling mixed data types in lists, or checking palindromes in other data structures, drop them in the comments — I’d love to try them next. #100DaysOfCode #365DaysOfCode #Python #LogicBuilding #TwoPointers #Lists #CodingJourney #LearnInPublic #AspiringDeveloper
To view or add a comment, sign in
-
-
Day 13/365: Tracking Daily Attendance with Dictionaries in Python 📊👨🏫 Today I worked on a simple but very practical problem in Python: updating a daily attendance record using a dictionary. 🔍 What this code does: I started with an attendance dictionary that stores how many days each student has attended so far. Then I created a today list that contains the names of students who attended class today. In this list, some names can appear more than once (for example, if the system logs multiple entries). Using a for loop, I go through each name in today and update the dictionary: attendance.get(name, 0) checks the current attendance count for that student. If the name is not already in the dictionary, it uses 0 as the default. Then I add 1 to this value and store it back in attendance[name]. In the end, print(attendance) shows the updated attendance record for all students. 💡 What I learned: How dictionaries are perfect for tracking counts or running totals for each item (like students, products, clicks, etc.). How dict.get(key, default) helps avoid errors when a key might not exist yet. How looping over a list and updating a dictionary can be used for real-world problems like: attendance systems, order frequency tracking in e‑commerce, counting events in logs or user actions. Day 13 done ✅ 352 more to go. If you have ideas like handling duplicate entries better, separating unique students per day, or generating attendance reports over a week/month, share them with me—I’d love to build on this next. #100DaysOfCode #365DaysOfCode #Python #LogicBuilding #Dictionaries #DataStructures #CodingJourney #LearnInPublic #AspiringDeveloper
To view or add a comment, sign in
-
-
🚀 Day 49 Today I explored Python’s HTMLParser and learned how to extract meaningful information from HTML snippets. 🔍 Key takeaways: • How to handle single-line and multi-line comments using handle_comment() • How to process text data inside HTML tags using handle_data() • The importance of ignoring unnecessary data like empty lines ('\n') • Understanding how parsers read content sequentially from top to bottom 💡 What I built: A Python program that reads HTML input and prints: ✔️ Single-line comments ✔️ Multi-line comments ✔️ Data content This task improved my understanding of how web data is structured and how parsers interpret it — a small step toward mastering web scraping and data processing! Consistency > Perfection. See you on Day 50 💻🔥 #Python #CodingJourney #LearningEveryday #HTMLParser #DeveloperLife
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