Ever wondered why Python sometimes says two equal-looking numbers are not equal? 🤔 Python Code: a = 0.1 + 0.2 b = 0.3 print(a == b) print(round(a, 1) == b) At first glance, 0.1 + 0.2 should be exactly 0.3. But Python works with binary floating-point values, not human-friendly decimals. So instead of storing 0.3, Python internally gets something extremely close to it — but not exactly the same. That tiny difference is enough to make a == b evaluate to False. Rounding brings both values into the same precision range, which is why the second comparison evaluates to True. This is the reason why, in real-world data science and analytics, direct float comparisons are avoided. A safer approach: Copy code Python import math math.isclose(a, b) Key takeaway: Numbers in Python can look equal, behave equal, and still be unequal in memory. #Python #DataScience #ProgrammingInsights #FloatingPoint #TechLearning #CodingConcepts
Python's Floating Point Equality Issue
More Relevant Posts
-
Today, I focused on learning Python Dictionaries, an essential data structure used for efficient data storage and retrieval through key–value pairs. Key concepts I covered include: • Creating and updating dictionaries • Accessing values using keys and the .get() method • Adding and removing elements using assignment and .pop() • Iterating through keys, values, and key–value pairs using .keys(), .values(), and .items() • Valid data types for dictionary keys (immutable types only) Additionally, I explored: Sorting dictionaries by keys Sorting dictionaries by values using lambda functions Practical Implementation: I implemented a program to count the frequency of unique characters in a string using dictionaries — a common real-world data processing task. Example: Input → rrsssstttt Output → { "r": 2, "s": 3, "t": 4 } This session helped reinforce how dictionaries improve performance and code readability in Python. #Python #DataAnalytics #LearningJourney #ProgrammingFundamentals #ContinuousLearning #PythonDictionaries
To view or add a comment, sign in
-
🚀 Learning Python String Methods — My Practice Notes Today I practiced important Python string functions that help in text processing and formatting. These methods are very useful in real projects and data handling. ✔ upper() → converts text to uppercase ✔ lower() → converts text to lowercase ✔ rstrip() → removes characters from right side ✔ replace() → replaces words in a string ✔ split() → splits string into list ✔ capitalize() → capitalizes first letter ✔ center() → aligns text at center with given width ✔ count() → counts occurrences of a word ✔ startswith() → checks starting text ✔ endswith() → checks ending text ✔ find() → finds position of a word ✔ swapcase() → swaps upper/lower case ✔ title() → capitalizes each word Practicing these methods helped me understand how powerful Python strings are for real-world applications. #Python #LearningPython #CodingPractice #StringMethods #BeginnerToPro https://lnkd.in/gYptz5A4
To view or add a comment, sign in
-
🐍 𝐏𝐲𝐭𝐡𝐨𝐧 𝐌𝐚𝐳𝐞 Recently, I shared a Python poll question that looks simple at first glance… But once you step inside, finding the exit isn’t that easy. Let’s take a look at the question: L1 = [1, 2, 3, 4, 5, 6] L2 = [a for a in L1 if a % 2] print(*L2, sep=", ") What do you think the output will be? a) 1,2,3,4,5,6 b) 2,4,6 c) 1,3,5 d) It raises an error This poll question points to a small but critical detail in Python that we often overlook without realizing it. 📖 I shared the background of the poll, why this question is so confusing, and a detailed evaluation in my Medium article. 👉 To find your way out of the Python Maze: https://shorten.ly/jD9j 👉 Our Poll Link : https://lnkd.in/dJ_TgXe8 💬 Answer it first, then read the article. Did you find the right path right away? 👇 Shared by İzzet ÖZDEMİR #PythonMaze #Python #DataScience #MachineLearning #Programming #Learning #CodeThinking
To view or add a comment, sign in
-
Python is a beautiful lie. (And this book is the truth.) 🐍 Most people love Python because it handles the "heavy lifting" for us. We call .sort() and it just works. We use a list and don’t think twice about memory. But reading “Data Structures and Algorithms in Python” by Goodrich, Tamassia, and Goldwasser": if you don’t understand the structures, you’re just driving a car without knowing how the engine works. I’m currently un-learning the "easy way" to master the "efficient way." Why this book changed my perspective: Abstract Data Types (ADTs): It’s not just about syntax; it’s about the mathematical model. The Cost of "Easy": Understanding why a simple insert(0, value) can destroy your program’s performance as data scales. Memory Management: Learning how Python actually handles dynamic arrays under the hood. I’m no longer just writing code that runs. I’m learning to write code that scales. If you're a Python dev, are you relying on the language to be smart for you, or do you know exactly what your code is doing to the CPU? hashtag #Python hashtag #SoftwareEngineering hashtag #DataStructures hashtag #Algorithms hashtag #ComputerScience hashtag #DeepLearning
To view or add a comment, sign in
-
At first, I skipped Iterator, Generator, and Decorator while revising Python. I thought they were confusing and not that important. But during revision, when I properly understood them, everything became clear — what they are, why they exist, and where Python actually uses them. ✨ Quick learning summary : 🔹 Iterator Used to go through data one value at a time. Example: reading large files, database records. 🔹 Generator An easier and smarter way to create iterators using yield. Used when working with large data, streams, or infinite sequences. 🔹 Decorator Used to add extra behavior to a function without changing its code. Commonly used for logging, authentication, caching . 👉 After understanding these concepts, Python feels more powerful and logical, not complex. 📌 Lesson learned: Never skip a topic just because it looks difficult. Once you understand the why, the how becomes easy. #Python #LearningJourney #CorePython #Iterator #Generator #Decorator #ProgrammingBasics #Revision #InnomaticsResearchLabs #AdvancedPython #Syntax #Example
To view or add a comment, sign in
-
-
Starting with my first tool 🛠️ In my Data Analytics journey the first tool on the list is Python, I don't know why it was arranged like that, but I will find out later. Python seems complicated, and not easy especially for us coming from a non- technical background, but I think there is still hope for us 😌. Today I got to learn about data types, variables, and keywords. Even some mathematical operations, where 'BODMAS' = 'PEMDAS' in python P= parenthesis () E= exponential ** M= multiplication* D= division / A= addition + S= subtraction - This is the order of mathematical operations in Python. Again, if you are having an issue installing and running python on your pc due to low RAM or ROM, or a low end pc, you can go to this website 'googlecollab.com' it has a pre-installed python feature and it runs smoothly on any PC, you can research more about it. What's one thing about Python you love, please share with us in the comments ✍️ #dataanalyticjourney #python #tech #economicsstudent #buildinpublic
To view or add a comment, sign in
-
-
When I was new to Python, syntax was not the real challenge.Become 2026 Data analysis Roadmap Free resources https://lnkd.in/dRJpwWvC Logic was. I could read code, but I didn’t understand how decisions were made or how programs repeated actions. Many beginners face the same issue. They learn variables on Day 1, then suddenly feel lost when conditions and loops appear. This is exactly why Day 2 in my Python series focuses only on control flow. This image breaks down how Python thinks: when to choose one path over another, how repetition works, and how small logical blocks become real programs. Instead of memorizing rules, beginners practice with simple logic problems and a number guessing game. This builds confidence early and removes the fear of loops and conditions. In 2026, strong Python users are not defined by advanced libraries first, but by how clearly they can think and structure logic. This series is designed to build that clarity step by step, one day at a time. Understanding logic early changes everything later. https://lnkd.in/dRJpwWvC — Shivam Saxena #Python #PythonLearningSeries #ControlFlow #PythonForBeginners #LearnPython #DataAnalytics #ProgrammingLogic #2026Skills #CareerInData
To view or add a comment, sign in
-
-
Back to the fundamentals today, and wow, understanding Variables and Data Types truly is the bedrock of everything else in Python! 🤯 I’ve been struggling recently with weird errors, and almost every time, the root cause was misunderstanding what data type I was actually working with. I finally feel like I leveled up today by focusing intensely on the "why" behind data types. Variables aren't just names; they are labels pointing to data, and Python needs to know if that data is text, a whole number, or a decimal to perform the right calculations. The simple definitions were crucial for me: * `int`: For counting things (1, 100). * `float`: Crucial for ML calculations where precision matters (3.14, 0.5). * `str`: Text sequences (like feature names or user input). * `bool`: The logic gates that make algorithms run (True or False). It’s amazing how much easier list slicing and mathematical operations become when you consistently check the type! I used `type()` liberally today, and it saved me so much frustration. Huge victory for this learning journey! 🥳 What Python fundamental concept did you find surprisingly tricky when you first started learning? Let’s share tips! 👇 #DataScience #Python #MachineLearning #LearningJourney #CodingFundamentals
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