In C, an integer takes 4 bytes. In Python, the number 1 takes 28 bytes. Why? As python is a "Dynamically Typed" language, it needs to store more than just the value 1. It needs to store "metadata" about that value so the interpreter knows what to do with it. How? In the CPython source code, every single thing is a PyObject. So when we create x = 1, following structure is created with it: 1. ob_refcnt (8 bytes): The Reference Counter. It tracks how many variables point to this object. 2. ob_type (8 bytes): A pointer to the "Type Object" (telling Python the datatype). 3. ob_size (8 bytes): For variable-sized objects (like lists) 4. The Actual Value (4-8 bytes): The actual number 1 Understanding this overhead explains why Python is memory-intensive being a dynamically typed language. I am trying to learn Python Internals in detail and will share my learnings. Do follow along and tell your experiences in comments. #Python #PythonInternals #SoftwareEngineering #BackendDevelopment
Onkar Lapate’s Post
More Relevant Posts
-
Mastering Python: A Quick Tip on lambda and filter() 🐍💡 Ever wondered how to make your code cleaner and more Pythonic for simple list operations? The lambda and filter() functions are your best friends! They are especially useful for concise, one-off functions where defining a full def block might be overkill. Here’s a simple example of how to filter even numbers from a list: python nums = [1, 2, 4, 5, 6, 7, 8, 9, 10] # Using a lambda function with filter() to get even numbers evens = filter(lambda x: x % 2 == 0, nums) print(list(evens)) # Output: [2, 4, 6, 8, 10] Use code with caution. ✅ Why this is great: Concise: Achieves a specific task in a single, readable line. Efficient: filter() returns an iterator, which is memory efficient for large datasets. Functional: Showcases a core concept of functional programming in Python. #Python #LambdaFunctions #CleanCode #PythonProgramming #TechTips #DataScience# Abhishek kumar # Harsh Chalisgaonkar # SkillCircle™
To view or add a comment, sign in
-
-
🧠 Python Feature That Feels Smart: set() for Removing Duplicates Most people do this 👇 unique = [] for x in nums: if x not in unique: unique.append(x) Python says… one line 😎 ✅ Pythonic Way unique = list(set(nums)) 🧒 Simple Explanation Imagine sorting marbles 🟢🔵🟢🔴 A set keeps only one of each color. Duplicates? Gone ✨ 💡 Why This Matters ✔ Removes duplicates fast ✔ Cleaner code ✔ Very common in interviews ✔ Great for data cleaning ⚠️ Important Note set() does not keep order. If order matters 👇 unique = list(dict.fromkeys(nums)) 💻 Python has tools that replace 10 lines of code with 1. 💻 Knowing them is what separates writing code from writing good code 🐍✨ #Python #PythonProgramming #PythonTips #LearnPython #CodingTips #Programming #SoftwareDevelopment #DataCleaning #DeveloperCommunity #TechCareers #CodeSmart #100DaysOfCode
To view or add a comment, sign in
-
-
Most Python bugs don’t happen because the logic is wrong. They happen because we keep solving common, boring problems in bad ways. Some Python libraries that helped me fix this: cattrs – helps handle structured data instead of messy dictionaries hypothesis – finds bugs by testing cases you didn’t think about pyrsistent – makes shared data safer and more predictable msgspec – shows how slow normal JSON handling can be watchfiles – reliable file watching without random issues datasketch – handles large-data problems in a simple way These libraries don’t make your code fancy. They make it more stable and harder to break. #Python #CleanCode #SoftwareEngineering #ProgrammingTips #DeveloperCommunity
To view or add a comment, sign in
-
-
🐍 Python Data Types — explained simply In Python, data types tell Python what kind of value you are storing. 🔢 int Whole numbers 👉 10, -5, 100 🔢 float Decimal numbers 👉 10.5, 3.14 🔤 str (string) Text / words 👉 "hello", "Python" ✅❌ bool (boolean) True or False 👉 True, False 📦 list Collection of values (changeable) 👉 [1, 2, 3] 📦 tuple Collection of values (not changeable) 👉 (1, 2, 3) 🗂️ dict (dictionary) Key–value pairs 👉 {"name": "Alex", "age": 25} 🔁 set Unique values only 👉 {1, 2, 3} 🧠 Easy trick to remember Numbers → int, float Text → str Yes/No → bool Group of values → list, tuple, set Key–value → dict 👉 Follow Pavan Kale for more simple Python & tech explanations. #Python #PythonBasics #DataTypes #TechForFreshers #ProgrammingBasics #LearnPython #CodingBeginner #LearningInPublic
To view or add a comment, sign in
-
Day 37 – Understanding How Python Stores Data Today, I am continuing on hash tables in Python, which is what powers dictionaries (dict). In simple terms: Python uses a smart system to store and find data almost instantly, instead of searching line by line. That’s why dictionaries are fast and used everywhere — from logins to APIs to caching. Today, I didn’t just read about how Python dictionaries work — I built a simple hash table from scratch in VS Code. What I did: Created a basic HashTable class Used Python’s hash() function to decide where data should live Stored values in buckets (lists) to safely handle collisions Retrieved values using keys, just like a real Python dict Even tested collisions by inserting keys that land in the same bucket I learned: Why dictionary keys must not change What a hash is (Python’s way of knowing where to store data) Why this concept matters for building fast and scalable systems This might look small, but it’s one of the ideas behind efficient backend and full-stack development. Slow progress is still progress. Understanding beats rushing. Which of the terms or concepts used here sounds too scary and unusual for you? Let me know, let's learn together 😊 #Day37 #LearningInPublic #Python #DataStructures #BackendBasics #Consistency
To view or add a comment, sign in
-
There is a one line trick to save about 50% RAM usage in Python. By default, Python objects are flexible but heavy. To have flexibility to store any attribute inside objects, every Python object carries a dictionary called __dict__. Each attribute of the object is mapped inside this underlying dictionary. This is why we can add new attributes to an object on the fly: user.new_attribute = "surprise!" That means building a backend system that creates millions of objects (users, transactions, events) will create millions of dictionaries too. But dictionaries are memory consuming because they use hash tables to stay fast. Solution: __slots__ If you know exactly which attributes your object will have, you can tell Python: reserve space just for these fields only. Impact - Memory: SlotsUser uses significantly less RAM (40% to 60%) Speed: Attribute access is slightly faster Strictness: You can’t add random attributes anymore Takeaway - When you don’t need that flexibility, __slots__ helps you keep things lean. I am trying to learn Python Internals in detail 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
-
-
Time Complexity in Python Operations In Python, performance issues rarely come from syntax. They come from misunderstanding how common operations scale as data grows. Key complexity considerations: - List access by index: constant time, but insertions and deletions in the middle are linear - Dictionary and set lookups: constant time on average, dependent on hashing - Membership checks: linear for lists, constant time for sets and dictionaries Sorting operations: typically O(n log n), regardless of data structure - Understanding these behaviors helps avoid hidden bottlenecks and supports writing code that scales predictably. Good performance starts with knowing how your code grows. 🚀 #Python #DataStructures #Algorithms #CodeOptimization #Performance
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
-
-
🚀 Day 23/100 | #100DaysOfCode with Python 🐍 Today I learned three super useful concepts that make Python code shorter, cleaner, and more powerful 👇 ✨ Lambda Functions Small, anonymous functions written in a single line. Perfect when the logic is simple and you don’t need a full function. 🔁 map() Function Used to apply the same operation to every element in a list or iterable. Great for transforming data quickly and efficiently. 🎯 filter() Function Helps extract only those values that match a condition. Super helpful when working with real-world data. What I loved today: Less code ✅ Better readability ✅ More confidence with Python ✅ Taking one step forward every day, no matter how small 💪 Consistency > Perfection 🚀 If you’re learning Python too, what did you practice today? Let’s share and grow 👇 #Day23 #PythonLearning #Lambda #MapFunction #FilterFunction #100DaysOfCode #CodingJourney #LearnToCode #DeveloperInMaking #DailyLearning
To view or add a comment, sign in
-
Python Data Structures explained — simply and practically 🧠🐍 Lists, Tuples, Sets, and Dictionaries are the foundation of almost every Python program — yet many developers use them without fully understanding when and why to choose each one. 👉 List → ordered & mutable 👉 Tuple → ordered & immutable 👉 Set → unique elements only 👉 Dictionary → fast key-value lookups Understanding these basics helps you write cleaner, faster, and more reliable Python code — whether you’re a beginner or revisiting fundamentals. That’s why I created this easy-to-reference cheat-sheet style guide with clear syntax and practical examples. #Python #PythonProgramming #Coding #DataStructures #LearnPython #ProgrammingTips #CheatSheet #TechCareers
To view or add a comment, sign in
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