𝗔 𝗣𝘆𝘁𝗵𝗼𝗻 𝗴𝗼𝘁𝗰𝗵𝗮 𝘁𝗵𝗮𝘁 𝗯𝗶𝘁𝗲𝘀 𝗲𝘃𝗲𝗿𝘆 𝗯𝗲𝗴𝗶𝗻𝗻𝗲𝗿 𝗲𝘅𝗮𝗰𝘁𝗹𝘆 𝗼𝗻𝗰𝗲. >>> 10 / 2 5.0 Wait... 5.0? Not 5? Python's division operator 𝘢𝘭𝘸𝘢𝘺𝘴 returns a float. Even when the result is a whole number. This seems like a minor detail until you try to use that result as a list index: → my_list[10 / 2] # TypeError! The fix is floor division: → 10 // 2 returns 5 (an integer) But here's another trap: floor division rounds toward 𝘯𝘦𝘨𝘢𝘵𝘪𝘷𝘦 𝘪𝘯𝘧𝘪𝘯𝘪𝘵𝘺, not toward zero. → -7 // 2 returns -4, not -3 Small details. Big consequences. The developers who know these quirks aren't necessarily smarter—they've just been burned by them before and learned. Now you know without the burn. I'm writing "Zero to AI Engineer: Python Foundations" in public. Follow along on Substack for behind-the-scenes updates and excerpts (link in comments). What Python gotcha caught you by surprise? #Python #Programming #SoftwareEngineering #TechCareers #LearnToCode
Python Division Gotchas: Floor Division and Negative Numbers
More Relevant Posts
-
Some scripts run. Some scale. That difference hit home while reading this 👇 🧠 “Professional code isn’t about cleverness. It’s about predictability.” For a long time, my Python scripts worked… but felt fragile. The shift wasn’t more syntax — it was better libraries and better thinking. 🔧 Tools like: pathlib → clean, cross-platform file handling loguru → real logging beyond print() A mindset of structure first, failures second, scale always Small choices. Big upgrade. From “it runs on my machine” to “this could ship.” 🚀 If you’re automating with Python, boring + predictable beats clever every time. #Python #Automation #SoftwareEngineering #CleanCode #DeveloperGrowth #LearningEveryday
To view or add a comment, sign in
-
-
𝐕𝐚𝐫𝐢𝐚𝐛𝐥𝐞𝐬 𝐬𝐨𝐮𝐧𝐝 𝐭𝐞𝐜𝐡𝐧𝐢𝐜𝐚𝐥. 𝐓𝐡𝐞𝐲’𝐫𝐞 𝐧𝐨𝐭. Body A variable is just a name for something you want to remember in your code. Instead of writing the same value again and again, you store it once and reuse it. That’s how programs stay clean and readable. 1. 𝑾𝒉𝒂𝒕 𝒂 𝒗𝒂𝒓𝒊𝒂𝒃𝒍𝒆 𝒊𝒔 A variable is a label that points to a value. Just like saving a contact name instead of memorizing a phone number. 2. 𝑯𝒐𝒘 𝒕𝒐 𝒂𝒔𝒔𝒊𝒈𝒏 𝒐𝒏𝒆 You create a variable using the equals sign: age = 20 This tells Python: store 20 under the name age. 3. 𝑹𝒆𝒂𝒍-𝒘𝒐𝒓𝒍𝒅 𝒆𝒙𝒂𝒎𝒑𝒍𝒆𝒔 name = "Alex" price = 2500 is_student = True These look like everyday things because that’s exactly what they represent. Once you get this, half of Python stops feeling confusing. 𝐃𝐫𝐨𝐩 𝐚 𝐯𝐚𝐫𝐢𝐚𝐛𝐥𝐞 𝐧𝐚𝐦𝐞 𝐲𝐨𝐮 𝐜𝐚𝐧 𝐜𝐫𝐞𝐚𝐭𝐞 𝐭𝐨𝐝𝐚𝐲. 𝐂𝐥𝐢𝐜𝐤 𝐭𝐡𝐞 𝐥𝐢𝐧𝐤 𝐭𝐨 𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫 𝐟𝐨𝐫 𝐨𝐮𝐫 𝐌𝐋 𝐁𝐨𝐨𝐭𝐜𝐚𝐦𝐩 𝐢𝐧 𝐭𝐡𝐞 𝐜𝐨𝐦𝐦𝐞𝐧𝐭𝐬 𝐬𝐞𝐜𝐭𝐢𝐨𝐧. #PythonBeginners #LearnPython #CodingBasics #TechStudents #MachineLearningJourney #HEMPI
To view or add a comment, sign in
-
𝗗𝗮𝘆 𝟭𝟰: 𝗦𝗲𝘁𝘀 𝗶𝗻 𝗣𝘆𝘁𝗵𝗼𝗻 🐍 𝗦𝗲𝘁𝘀: 🔹 Sets are unordered collections of items 🔹 Elements are unique (no duplicate values) 🔹 Items are separated by commas and enclosed in curly brackets { } 🔹 Sets do not maintain order 𝗖𝗿𝗲𝗮𝘁𝗶𝗻𝗴 𝗮 𝗦𝗲𝘁: 🔹 s = {1, 2, 3} 🔹 Use set() to create an empty set : s = set() ⚠️ {} creates an empty dictionary, not a set 𝗦𝗲𝘁 𝗢𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝘀: 1️⃣𝗨𝗻𝗶𝗼𝗻 (|) → combines elements 2️⃣𝗜𝗻𝘁𝗲𝗿𝘀𝗲𝗰𝘁𝗶𝗼𝗻 (&) → common elements 3️⃣𝗗𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝗰𝗲 (-) → elements in one set but not the other 4️⃣𝗦𝘆𝗺𝗺𝗲𝘁𝗿𝗶𝗰 𝗗𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝗰𝗲 (^) → elements not common 📝Important Notes: 🔹 Sets do not support indexing or slicing 🔹 Elements must be immutable (int, string, tuple) Building strong Python fundamentals, one concept at a time 🚀 #Python #Tuples #LearningPython #LearningInPublic #AspiringDataScientist #Consistency
To view or add a comment, sign in
-
𝗗𝗮𝘆 𝟭3: 𝗧𝘂𝗽𝗹𝗲𝘀 𝗶𝗻 𝗣𝘆𝘁𝗵𝗼𝗻 🐍 🔹 Tuples are ordered and immutable collections of items, separated by commas and enclosed in round brackets. 🔹 Items can be of multiple data types 🔹 Once created, tuples cannot be changed, added to, or deleted 𝗖𝗿𝗲𝗮𝘁𝗶𝗻𝗴 𝗧𝘂𝗽𝗹𝗲𝘀: ✔ Single-item tuple (comma is mandatory) ✔ Using parentheses: (1, 2, 3) ✔ Without parentheses: tup = 1, 2, 3 𝗖𝗼𝗺𝗺𝗼𝗻 𝗢𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝘀: ✔ Indexing and slicing (same as lists) ✔ Unpacking – assign tuple values to multiple variables ✔ Concatenation – combine tuples using + 📝𝗡𝗼𝘁𝗲: 🔸 Tuples cannot be modified directly. 🔸 To make changes, convert the tuple to a list, modify it, and convert it back to a tuple. Building strong Python fundamentals, one concept at a time 🚀 #Python #Tuples #LearningPython #LearningInPublic #AspiringDataScientist #Consistency
To view or add a comment, sign in
-
After working with #Python daily as a #DataEngineer, this article was a reminder that productivity bottlenecks are rarely about algorithms — they’re about the tools we ignore. ⚙️🐍 The biggest gains often come from “boring” libraries like pathlib and rich that reduce cognitive load, bugs, and manual work. Cleaner file handling, better logs, faster automation — small shifts, compounding impact. Sometimes the upgrade isn’t new tech. It’s finally respecting the basics you underestimated. #DataEngineering #Python #Automation #DeveloperProductivity #ETL #DataPipelines #SoftwareEngineering #LearningInPublic
To view or add a comment, sign in
-
🐍 Day 22 — Functions in Python Day 22 of #python365ai 🧩 Functions group reusable code. Example: def greet(name): print("Hello", name) 📌 Why this matters: Functions improve readability and reduce repetition. 📘 Practice task: Write a function that adds two numbers. #python365ai #PythonFunctions #CleanCode #LearnPython
To view or add a comment, sign in
-
-
A basic idea that cleared a lot of confusion for me was realizing that Python Dictionaries are like real-world folders: you don’t search for information by its position, but by its unique label (the Key). ⚡ Today, as part of the #15DayChallenge, I dived deep into Day 8: Dictionaries. Unlike lists where you use index numbers, dictionaries allow us to map "Key: Value" pairs. This makes retrieving data incredibly fast and intuitive. I practiced: ✅ Creating and modifying dictionaries ✅ Using methods like .get(), .keys(), and .values() ✅ Handling nested dictionaries for complex data structures Understanding how to efficiently store and access data is a game-changer for writing clean, readable code! NativesPlug @locus.ioe #LOCUS2026 #NativesPlug #LearningChallenge #15DayChallenge #NepalTech #LearnAndWin #PythonProgramming #CodingJourney
To view or add a comment, sign in
-
Diving Deeper into Python Strings! Until now, I was building strings in the old-school way: using + to concatenate and str() to convert numbers. It works… but it’s messy. Today, I explored a cleaner, more powerful approach: format(). Here’s what I learned: {} are placeholders for variables. .format() handles type conversions automatically, no more str() headaches! Named placeholders make strings readable and flexible, even if variable order changes. Format numbers, align text, and make outputs neat, perfect for prices, tables, logs, or debug messages. 💡 String formatting isn’t just cleaner syntax, it makes your code readable, maintainable, and professional. Once you get it, your logs and outputs will look polished! #Python #Coding #StringFormatting #CleanCode #LearnPython #ProgrammingTips
To view or add a comment, sign in
-
-
Late-night debugging teaches you one thing fast: tools matter 🕒🐍 I recently read a piece on Python libraries that quietly transform messy scripts into calm, production-ready automation — and it hit close to home. Key takeaway 👇 It’s not always about new frameworks or rewrites. Sometimes, the right library removes entire categories of bugs. 📌 Example: Using tools like pathlib means: ✅ No string-based path chaos ✅ Cleaner, readable file automation ✅ Fewer OS-specific surprises Small changes. Massive payoff. The kind that saves hours and your sanity. If you write Python regularly, this is a reminder worth revisiting. 🚀 #Python #Automation #CleanCode #DeveloperExperience #Productivity
To view or add a comment, sign in
-
-
🌙 Day 12/100 | #100DaysOfCode 🚀 Another productive day with Python 🐍✨ Today, I learned about Sets and how powerful they are when working with unique data. Here’s what I explored today 👇 🔹 What is a Set? A set stores only unique values — no duplicates allowed. Super useful for removing repeated data. 🔹 Union ( | ) Combine two sets and get all unique elements from both. 🔹 Intersection ( & ) Find common elements between two sets. 🔹 Difference ( - ) Get elements that are in one set but not in the other. 🔹 Symmetric Difference ( ^ ) Elements that are in either of the sets but not in both. 🔹 Useful Methods I practiced: • add() • remove() • discard() • clear() • copy() Sets are fast, clean, and very helpful in real-world data problems 🔥 Learning step by step, staying consistent, and enjoying the process 💪 One day, one concept, one step closer to my goals 🚀 #Python #SetInPython #100DaysOfCode #LearningJourney #CodingDaily #DataStructures #TechSkills #ConsistencyIsKey
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
https://substack.com/@samuelochaba?utm_campaign=profile&utm_medium=profile-page