Although it may not be a big deal in other object oriented language to know the difference between Class and Object, it is a big deal in Python. This is especially evident and important when using libraries and/or frameworks that expects you to pass a callback function as one of the arguments to its own function or method. Why Python? Cause Python expects an extra "self" parameter to be passed in instance methods that other PLs don't. You'll encounter this unique behavior when you pass a class, instead of an object, along with the callable as this is a function (not a method) that expects "self", thus you get too many arguments, expected "n" arguments but got "n+1"... type of error, because of that extra argument being passed by Python. And this is why I always tell people that I mentor to not ignore or skip the basics or essentials, as this knowledge becomes critically valuable in most edge cases. #python #class #object
Python Class vs Object: Understanding the Difference
More Relevant Posts
-
🧠 “Interesting Python Nugget” (Lists) Python List Trick You’ll Actually Use Did you know you can remove duplicates from a list in ONE line? nums = [1, 2, 2, 3, 4, 4] unique_nums = list(set(nums)) ✔ Simple ✔ Fast ✔ Super handy for real projects Python has tons of these tiny gems that save time and make code cleaner. 📬 We explain one Python concept every day — short, clear, and practical. Want more? Subscribe and learn Python daily ✨ link in the comments Please sign up and follow #PythonChallenge #PythonLearning #CodeChallenge #PythonDaily #PyDaily
To view or add a comment, sign in
-
-
Day 10/60 🚀 60 Days Python Series 🐍 🔥 How to assign a variable to 0 in Python There are multiple ways to do the same thing in Python 👨💻 Understanding this helps you write clean and flexible code. Examples you’ll learn today: ✔ x = 0 ✔ x = int() ✔ x = 1 - 1 ✔ x = abs(-0) Master the basics and Python becomes easy 💡 📌 Save this post for revision 💬 Comment “python” if you’re following the series ➡️ Follow for daily Python tips #60dayspython #pythonseries #learnpython #pythonbasics #codingreels #programminglife #logicbuilding #pythonforbeginners
To view or add a comment, sign in
-
🐍 Day 3 of My Python Journey: Variable Re-initialization Today I learned something fundamental yet powerful - variables in Python are incredibly flexible! Unlike some languages where you're locked into a data type, Python lets you reassign variables to completely different types: python x = 42 # I'm an integer x = "Hello" # Now I'm a string x = [1, 2, 3] # Now I'm a list Key takeaways: Variables are just labels pointing to objects in memory You can change what a variable points to at any time Python automatically handles the type conversion The old value gets garbage collected if nothing else references it Practical use case I tried: python user_input = input("Enter a number: ") # String user_input = int(user_input) # Now it's an integer result = user_input * 2 This flexibility makes Python beginner-friendly, but I'm learning to be mindful about keeping my code readable and maintaining consistent variable purposes. What's a Python concept that surprised you when you first learned it? #Python #100DaysOfCode #LearnPython #PythonProgramming #CodingJourney #TechLearning
To view or add a comment, sign in
-
-
Why range(1,000,000) is cheap, but list(range(1,000,000)) is costly in Python? TL;DR: Iteration Protocol in Python needs to know only next item and not full list. The "Next Page" Rule Iteration in Python isn't about having a collection of items; it’s about knowing how to get the next item. Two special methods make this possible: 1. __iter__() → tells Python “I can be looped over” 2. __next__() → returns the next value, one at a time When there’s nothing left, StopIteration tells Python to stop the loop. Why this matters? When we use a list, we pay for all the memory upfront. When we use the Iteration Protocol, we only pay for one item at a time. This is called Lazy Evaluation. Takeaway - If the object represents a collection or a stream of data, implement __iter__ and __next__. It makes the code more memory-efficient and much more "Pythonic." I’m deep-diving into the Python protocols this week and will share my learnings. Do follow along and tell your experiences in comments. #Python #PythonInternals #SoftwareEngineering #BackendDevelopment
To view or add a comment, sign in
-
-
Am I too late? I just discovered match-case in Python! If you have used "switch-case" in other languages, "match-case" is Python’s way of doing something similar, but with more flexibility. It helps handle multiple conditions in a clean, readable way. Where it really comes in handy: 1. Routing logic in applications (choosing actions based on user input). 2. Handling different types of messages or events. 3. Simplifying long if / elif / else chains. 4. Working with structured data like tuples, lists, or dictionaries. Honestly, it makes your code much easier to read and maintain when there are multiple possibilities to consider. If you are just finding out about it like I did, I would definitely recommend checking it out and getting familiar with how it works, you might be surprised. If you have used it before, I’d love to hear your take on it. #Python #BackendDevelopment
To view or add a comment, sign in
-
Why 60 * 60 * 24 costs the same as 86400 in Python? TL;DR: Python evaluates it once at compile time! You might think writing out the math makes the code slower because Python has to do the multiplication every time. When Python compiles source code into Bytecode, it uses an optimiser (Peephole) that looks for constants. This is called Constant Folding. It’s not just for numbers! Python also folds small strings. "Deep" + "Tech" becomes "DeepTech" in the bytecode. Takeaway: -> Never sacrifice readability for a "assumed" performance gain in constants. -> Python’s compiler is not just a translator, it’s an optimiser. -> Compiler handles the math smartly, so you can focus on writing code that humans can actually read! I’m deep-diving into Python internals and performance. Do follow along and tell your experiences in comments. #Python #PythonInternals #SoftwareEngineering #BackendDevelopment
To view or add a comment, sign in
-
-
A Python script often starts as a small helper. Something quick. Something obvious. Months later, the same script becomes part of a larger flow- feeding analysis, reports, or decisions. When results are questioned, the instinct is to check the code. But more often, the real lesson appears elsewhere: the script did exactly what it was designed to do even if the context around it has changed. Python remains stable. Expectations don’t. #Python #DataAnalytics #AnalyticsReality
To view or add a comment, sign in
-
Day 19: Top Learning 🧠 | Built-in Functions in Python Built-in functions are Python’s superpower ⚡ Instead of writing long logic, Python gives ready-made tools to work faster, cleaner, and smarter. From string methods like lower(), strip(), replace() to list functions like append(), sort(), len() and number functions like round(), abs(), sum() - 👉 This is how real Data Analysts save time and write efficient code. Less code. More clarity. Better analysis. 🚀 Python is becoming more practical and powerful. Satish Dhawale SkillCourse #Python #DataAnalytics #LearningJourney #BuiltInFunctions
To view or add a comment, sign in
-
-
Why .join() is faster than str1 + str2 in Python? Why string concatenation gets really slow in Python? Strings are immutable in Python. When we write str1 + str2, following steps are done - 1. Request a brand new block of memory large enough for both. 2. Copy every single character from str1 and str2 into the new block. 3. Destroy the old strings (eventually) If we do this 10,000 times in a loop, we are copying millions of characters over and over again. When we use ''.join(list_of_strings), Python is significantly smarter. It performs following 2 pass operation - 1. It iterates through the entire list once to calculate the total length of the final string. 2. it allocates one single block of memory of that exact size and copies all the strings into their respective slots at once. Instead of n reallocations and n copies, one allocation and one copy! Takeaway - -> Need to join 2 or 3 strings - a + b is fine and very readable. -> Need to join strings in a loop - Always collect them in a list first and use ''.join(my_list) at the very end. I’m deep-diving into Python internals and performance. Do follow along and tell your experiences in comments. #Python #PythonInternals #SoftwareEngineering #BackendDevelopment
To view or add a comment, sign in
-
More from this author
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
Thanks Dennis. This is a wealth of experience that needs to be told.