📘 Day 3 — Lists, If Conditions, For Loops… and Why Indentation Matters! Today’s learning felt like the moment Python started behaving like a real analysis tool. I covered: 🔹 Lists → storing multiple values 🔹 If Conditions → applying logic 🔹 For Loops → automating repetition 🔹 Indentation → the rule that makes everything work First — Lists Just like a column in Excel, Python lets us store multiple values together: marks = [65, 72, 58, 90, 48] Second — If Condition This allows Python to make decisions based on rules: if mark > 60: print("Pass") else: print("Fail") Third — For Loop Instead of checking each value manually, Python can go through the whole list: for mark in marks: if mark > 60: print("Pass") else: print("Fail") Now the Most Important Part — Indentation In many tools, spacing is just for readability. But in Python, indentation defines the structure of the code. Python uses indentation to understand: ✔ What belongs inside the loop ✔ What belongs inside the condition ✔ Where logic starts and ends Notice how everything inside the loop is indented: for mark in marks: if mark > 60: print("Pass") If indentation is wrong, Python throws an error — even if the logic is correct. So the key rule I learned today: 👉 Same logic block = Same indentation (usually 4 spaces) Today felt like moving from “writing code” to “teaching Python how to think through data.” #PythonLearning #DataAnalyticsJourney #codebasics #OnlineCredibility
Mastering Python Basics: Lists, If Conditions, Loops & Indentation
More Relevant Posts
-
Day 17 – Strings, Lists & Practical Logic Building in Python Today’s session was a mix of real-world logic building and deeper practice with strings and lists in Python. I started with a simple electricity bill calculation program using conditional statements. It helped me understand how tier-based logic works in real-life scenarios and how to structure conditions properly using if-elif-else. Strings – More Practice Revised and practiced important string methods: upper() and lower() for case conversion isupper() and islower() for validation capitalize() vs title() replace() with control over number of replacements This reinforced how strings are immutable and how every operation returns a new modified string. Lists – Slicing & Methods in Depth Worked extensively on list operations and understood the difference between modifying and non-modifying methods. Slicing Practice: Normal slicing Step slicing Reverse slicing Skipping elements using step values List Methods Explored: append() → add single element extend() → add multiple elements from iterable insert() → add element at specific index remove() → remove first occurrence pop() → remove by index (returns removed value) clear() → empty the list index() → find position of element sort() → modifies original list sorted() → returns new sorted list reverse() → reverse list order join() → join list elements into a string I also observed: How insert() behaves with negative and out-of-range indexes Difference between sort() and sorted() How extend() works differently with list, tuple, and set Key Takeaways Understanding method behavior is more important than just memorizing syntax Some methods modify the original list, others return new values Real learning happens when testing edge cases Logic building is improving step by step Day 17 was more about strengthening fundamentals and building clarity in how Python handles data structures. #Python #PythonLists #PythonStrings #ProgrammingBasics #DataStructures #CodingPractice #DailyLearning #ProblemSolving #LearnToCode #SoftwareDevelopment
To view or add a comment, sign in
-
Day 18: Scope and Precision — The Limits of Logic 🌐 As your programs grow, you'll start having variables with the same names in different places. How does Python know which one to use? And when doing math, how many decimals can Python actually "remember"? 1. Local vs. Global Scope Think of Scope as the "area of visibility" for a variable. Global Scope: Variables defined at the top level (outside any function). They can be read from anywhere in your script. Local Scope: Variables defined inside a function. They only exist while that function is running. Once the function ends, the variable is deleted. 💡 The Engineering Lens: Avoid using too many Global variables. If every function can change a variable, it becomes a nightmare to track down bugs. Keep data "Local" whenever possible! 2. The LEGB Rule: Python’s Search Engine When you call a variable name, Python searches in a very specific order to find it. This is the LEGB rule: Local: Inside the current function. Enclosing: Inside any nested "parent" functions. Global: At the top level of the file. Built-in: Python’s pre-installed names (like len or print). 3. Precision: The Decimal Limit When you use a Float (a decimal number), Python has to fit that number into a fixed amount of memory. Maximum Precision: Python floats are typically "double-precision" (64-bit). This means they can hold about 15 to 17 significant decimal digits. The Default: When you perform a calculation, Python will show as many decimals as are relevant, but it stops being accurate after that 15–17 digit mark. 💡 The Engineering Lens: Because of this limit, 0.1 + 0.2 often equals 0.30000000000000004. If you are building a banking app or a scientific tool where you need infinite precision, don't use floats! Use Python’s decimal module instead. #Python #SoftwareEngineering #CleanCode #ProgrammingTips #DataPrecision #LearnToCode #TechCommunity #PythonDev
To view or add a comment, sign in
-
I just finished implementing 10 classical hypothesis tests from scratch in Python — no stats libraries, just numpy. Each test is built step by step, then verified against scipy.stats to confirm correctness: Welch's t-test (independent & paired) One-way ANOVA (Welch's) Chi-squared & Fisher's Exact Pearson & Spearman correlation Mann-Whitney U & Wilcoxon Signed-Rank Shapiro-Wilk normality test The goal wasn't to reinvent the wheel — it was to understand what's actually happening inside these black boxes. Each test comes with a visualisation: rejection regions on the test distribution, rank strip plots, Q-Q plots, residual heatmaps — all built to make the mechanics visible, not just the result. Code and full write-up on GitHub 👇 https://lnkd.in/d6JFnjE2
To view or add a comment, sign in
-
𝐍𝐮𝐦𝐏𝐲 𝐁𝐨𝐨𝐥𝐞𝐚𝐧 𝐓𝐫𝐚𝐩 I’m still at the very beginning of my Python journey. But even with my tiny amount of experience, I already hit a subtle NumPy trap that can easily sneak into real code. Python is full of surprises — even at the very beginning It happens when you create an untyped NumPy array and fill it with a function that should return booleans… …but sometimes returns 𝙉𝙤𝙣𝙚 when processing fails. At first, you expect a clean boolean array — because the function normally returns 𝙏𝙧𝙪𝙚 or 𝙁𝙖𝙡𝙨𝙚. But NumPy has other plans. Here’s the trap 👇 🟥 𝟏) 𝐔𝐧𝐭𝐲𝐩𝐞𝐝 𝐚𝐫𝐫𝐚𝐲 + 𝐚 𝐟𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐭𝐡𝐚𝐭 “𝐬𝐡𝐨𝐮𝐥𝐝” 𝐫𝐞𝐭𝐮𝐫𝐧 𝐛𝐨𝐨𝐥𝐞𝐚𝐧𝐬 𝒂𝒓𝒓 = 𝒏𝒑.𝒆𝒎𝒑𝒕𝒚(10) # 𝒏𝒐 𝒅𝒕𝒚𝒑𝒆 𝒂𝒓𝒓[𝒊] = 𝒎𝒚_𝒇𝒖𝒏𝒄() # 𝑻𝒓𝒖𝒆 / 𝑭𝒂𝒍𝒔𝒆 ... 𝒐𝒓 𝑵𝒐𝒏𝒆 You expect a clean boolean array because the function usually returns 𝙏𝙧𝙪𝙚/𝙁𝙖𝙡𝙨𝙚. But if even one value is 𝙉𝙤𝙣𝙚, NumPy must pick a type that can hold all values. 🟦 𝟐) 𝐍𝐮𝐦𝐏𝐲 𝐬𝐢𝐥𝐞𝐧𝐭𝐥𝐲 𝐬𝐰𝐢𝐭𝐜𝐡𝐞𝐬 𝐭𝐨 𝐝𝐭𝐲𝐩𝐞=𝐨𝐛𝐣𝐞𝐜𝐭 𝒂𝒓𝒓𝒂𝒚([𝑻𝒓𝒖𝒆, 𝑭𝒂𝒍𝒔𝒆, 𝑵𝒐𝒏𝒆, ...], 𝒅𝒕𝒚𝒑𝒆=𝒐𝒃𝒋𝒆𝒄𝒕) Impact: no vectorization logical operations break masks behave unpredictably performance collapses You think you have a NumPy boolean array. You actually have a Python object array. 🟩 𝟑) 𝐓𝐡𝐞 𝐬𝐢𝐥𝐞𝐧𝐭 𝐜𝐨𝐧𝐯𝐞𝐫𝐬𝐢𝐨𝐧 𝐭𝐫𝐚𝐩 Trying to fix it: 𝒂𝒓𝒓 = 𝒏𝒑.𝒆𝒎𝒑𝒕𝒚(10, 𝒅𝒕𝒚𝒑𝒆=𝒃𝒐𝒐𝒍) 𝒂𝒓𝒓[𝒊] = 𝒎𝒚_𝒇𝒖𝒏𝒄() NumPy converts: 𝑵𝒐𝒏𝒆 → 𝑭𝒂𝒍𝒔𝒆 (silently) Impact: 👉you lose the meaning of “no result” 👉your data becomes wrong 👉the bug becomes invisible ⭐ 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Same code. Same function. Two completely different arrays. NumPy’s dtype inference can hide subtle bugs — and I found this one with almost no Python experience. 𝐂𝐮𝐫𝐢𝐨𝐮𝐬 𝐭𝐨 𝐤𝐧𝐨𝐰: 👉 Have you ever run into this behavior? 👉 Or another NumPy dtype surprise? #python #numpy #datascience #cleanCode #devTips #programming
To view or add a comment, sign in
-
-
Ever explained Duck Typing in Python to someone and watched their face go from 😃 → 🤯 in 3 seconds? Here’s how I tried explaining it to a friend: Friend: “How does Python know if something is a duck?” Me: Python doesn’t care if it’s a duck 🦆, a robot 🤖, or a developer pretending to work on Friday afternoon 😅 If it walks like a duck and quacks like a duck, Python just says: "Cool… must be a duck." Example 👇 class Duck: def quack(self): print("Quack!") class Person: def quack(self): print("I can imitate a duck!") def make_it_quack(obj): obj.quack() make_it_quack(Duck()) make_it_quack(Person()) Python: "Both quack? Perfect. I’m not asking for ID." Meanwhile in some other languages: "Excuse me sir, please submit 4 forms, 2 interfaces, and a type certificate before quacking." 🧾 That’s the beauty of Python — behavior matters more than type. So remember: In Python, nobody asks what you are. They only check what you can do. And honestly… that’s a life lesson too. 😄 #Python #DuckTyping #ProgrammingHumor #LearnToCode #PythonDeveloper #CodingLife #SoftwareEngineering #TechHumor #DeveloperLife
To view or add a comment, sign in
-
🚀 Day 6/60 – Loops in Python (Automate Repetition Like a Pro) Writing the same code again and again? ❌ Let Python do it for you ✅ That’s what loops are for 👇 🔁 What is a Loop? A loop lets you repeat a block of code multiple times. 🔹 1️⃣ For Loop (Most Used) for i in range(5): print(i) 👉 Output: 0 1 2 3 4 🔹 2️⃣ Loop Through List fruits = ["apple", "banana", "mango"] for fruit in fruits: print(fruit) 🔹 3️⃣ While Loop count = 0 while count < 5: print(count) count += 1 ⚡ Real Example for i in range(1, 6): print("Hello", i) 👉 Prints "Hello" 5 times ❌ Common Mistake (Infinite Loop) count = 0 while count < 5: print(count) ❌ This never stops! Correct: count += 1 🔥 Pro Tip Use range(start, stop, step) 👇 for i in range(1, 10, 2): print(i) 👉 1, 3, 5, 7, 9 🔥 Challenge for today Write a program: 👉 Print numbers from 1 to 10 👉 Print only even numbers Comment “DONE” when finished ✅ Follow Adeel Sajjad to stay consistent for 60 days 🚀 #Python #LearnPython #PythonProgramming #Coding #Programming
To view or add a comment, sign in
-
-
💡 𝗪𝗵𝘆 𝗱𝗼𝗲𝘀 𝗣𝘆𝘁𝗵𝗼𝗻 𝗸𝗲𝗲𝗽 𝘁𝗮𝗹𝗸𝗶𝗻𝗴 𝘁𝗼 𝗶𝘁𝘀𝗲𝗹𝗳? 🐍🤔 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
To view or add a comment, sign in
-
-
I used to think strings were the “easy” part of Python… today proved me wrong. 🐍 Day 04 of my #30DaysOfPython journey was all about strings, and honestly, this topic felt way more powerful than I expected. A string is basically any data written as text — and it can be written using single quotes, double quotes, or triple quotes. Triple quotes also make multiline strings super easy. Today I explored: 1. len() to check length 2. Concatenation to join strings together 3. Escape sequences like \\n, \\t, \\\\, \\', \\" 4. Old style formatting with %s, %d, %f 5. New style formatting with {} 6. Indexing and unpacking characters 7. Reversing a string with str[::-1] And then came the string methods… that part felt like unlocking a toolbox: capitalize(), count(), startswith(), endswith(), find(), rfind(), format(), index(), rindex(), isalnum(), isalpha(), isdigit(), isnumeric(), isidentifier(), islower(), isupper(), join(), strip(), replace(), split(), title(), swapcase() What hit me today was this: strings are everywhere. Names, messages, input from users, file data, logs, even the little things we ignore at first. So yeah — not “just text.” More like one of the most important building blocks in programming. Github Link - https://lnkd.in/gUkeREkz What was the first Python topic that looked simple but turned out to have way more depth than expected? #Python #LearnPython #CodingJourney #30DaysOfPython #Programming #DeveloperJourney
To view or add a comment, sign in
-
Stop Googling the same Python functions over and over. 🔴 Bookmark this instead. 👇 Putting together a cheat sheet of every built-in Python function beginners actually need - organized by category so you can find what you want in seconds: 📊 Numbers → abs(), round(), min(), max(), sum(), pow() Do math without reinventing the wheel. 🔤 Strings → len(), upper(), lower(), split(), join(), replace() Text wrangling made painless. 📋 Lists → append(), extend(), insert(), pop(), remove(), sort() You'll use these every single day. 🔗 Tuples & Sets → count(), index(), add(), update(), remove(), clear() Immutable data + unique elements = fewer bugs. 🔄 Control Flow → print(), input(), type(), range(), enumerate() The backbone of every loop and script you'll write. 🎲 Random & Type Conversion → random(), randint(), choice(), int(), float(), str() Simulations, transformations, and quick conversions. ⚙️ Functions → def, lambda, return, map() Write it once. Use it everywhere. ⚠️ Error Handling → try, except, raise, assert, finally Because "it works on my machine" isn't a strategy. Here's the thing most tutorials won't tell you: Memorizing syntax doesn't make you a developer. Building things does. Pick one category above. Open a blank .py file. Break something. Fix it. That's the loop. 🚀 These fundamentals are the difference between someone who "knows Python" and someone who builds with Python. Drop your most-used Python function in the comments. 👇 #Python #Programming #DataScience #SoftwareDevelopment #Coding
To view or add a comment, sign in
-
-
🐍 Python Data Types – Easy Memory Cheat Sheet When I started learning Python, remembering all the methods for List, Dictionary, Set, and String felt overwhelming. Instead of memorizing everything randomly, I discovered a simple trick: group methods by their functionality. 🔹 List → AROC Add: append(), insert(), extend() Remove: remove(), pop(), clear() Order: sort(), reverse() Check: index(), count() 🔹 Dictionary → AUR Access: keys(), values(), get() Update: update(), setdefault() Remove: pop(), popitem(), clear() 🔹 Set → ARM Add: add(), update() Remove: remove(), discard() Math operations: union(), intersection(), difference() 🔹 String → CCFS Clean: strip(), replace(), split() Check: isalpha(), isdigit() Format: lower(), upper(), title() Search: find(), count(), startswith() 💡 Developer Tip: You don’t need to memorize every method. Use: dir(list), dir(dict), dir(set), dir(str) to explore them interactively. 📌 Sharing this cheat sheet to help beginners learn Python faster. If you're learning Python, this might save you hours of confusion! #Python #PythonProgramming #CodingTips #LearnPython #Programming #SoftwareDevelopment
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