Day 3 of #30DaysOfPython ✅ Today Python started making decisions. So did I. 🔄 Control flow: if, elif, else, and loops (for and while). This is where code starts to *feel* like logic, not just instructions. Turns out, Python reads your if-elif chain from top to bottom and stops at the first True condition. I had my conditions backwards and everything was coming back😂 What I learned today: • elif is just a cleaner way to chain conditions • range() is weirdly intuitive once you stop fighting it • Infinite while loops are terrifying until you find the break statement • Indentation errors are my personal villain Day 3 done. Code is slowly starting to feel less like a foreign language. 👇 For loops or while loops — which do you use more day-to-day? #Python #30DaysOfPython #ControlFlow #CodeNewbie #MachineLearning
Python Control Flow: If, Elif, Else, Loops
More Relevant Posts
-
Day 5 of #30DaysOfPython ✅ Today I met two of Python's most powerful data structures. One of them already feels like home. The other? Slightly chaotic. Lists and dictionaries. Day 5. Lists made sense quickly — they're just ordered collections. I can store things, loop through them, sort them, slice them. Intuitive. Dictionaries? At first, the key-value pair concept felt abstract. The bug that got me today? I threw both strings and integers into the same list and tried to sort it. Python did not appreciate that. TypeError showed up like an old enemy. Day 5 done. 25 more to go! 👇 Lists vs dictionaries — when do you reach for one over the other? #Python #30DaysOfPython #DataStructures #StudentLife #AIML
To view or add a comment, sign in
-
-
Day 18 revision done. Operators. If/Else. Match statements. While loops. For loops. Not just reading through notes this time actually writing the code out, making mistakes, fixing them and doing it again until it felt natural. And honestly? It's working. The things that confused me the first time around are starting to make sense now. I finally get why // and % are different. I understand why indentation is not optional in Python. I know when to use a while loop vs a for loop. Revision isn't glamorous. There's no big aha moment. It's just you sitting down, doing the work and trusting that repetition builds confidence. And slowly it is making sense It is finally sticking and guess what I'm happy. Because Python is one of the most amazing tools used in the data space and I'm out here learning it on my own. Day 19 is next. Let's keep going. #Python #100DaysOfCode #SelfTaught #GrowthMindset #DataAnalysis #W3schools
To view or add a comment, sign in
-
Most implementations of the State pattern in Python look very “clean”. Lots of small classes. A base interface. One class per state. But if you’ve ever worked with one in a real project, you know the downside: transitions are scattered, behaviour is hard to see in one place, and adding new states often means touching multiple files. In today’s video, I rebuild the State pattern in a very different way. Instead of relying on inheritance, I make the state machine explicit as data and use decorators to define transitions. The result is a small, reusable engine where the entire flow becomes visible at a glance. If you’re interested in writing Python that’s easier to reason about and extend, this is a pattern worth understanding. 👉 Watch here: https://lnkd.in/e9Y3xGNF. #python #softwaredesign #designpatterns #statemachine #cleancode
To view or add a comment, sign in
-
-
Beyond String Concatenation When I started, I used to concatenate strings the old-school way. It was messy, prone to errors, and hard to read The Problem: Using + requires manual type conversion (like str(21)) and gets confusing with all the extra quotes and spaces Solution: F-strings Introduced in Python 3.6, F-strings makes your code: ✅ Readable: You see the full sentence structure ✅ Fast: They are more efficient than older methods ✅ Flexible: You can perform math or call methods directly inside { } It’s a small concept, but it’s one of the easiest ways to make code look 10x more professional. #Python #30DaysOfCode #BCA #LearningInPublic #Day21 #JECRC Day 21/30
To view or add a comment, sign in
-
-
Most implementations of the State pattern in Python look very “clean”. Lots of small classes. A base interface. One class per state. But if you’ve ever worked with one in a real project, you know the downside: transitions are scattered, behaviour is hard to see in one place, and adding new states often means touching multiple files. In today’s video, I rebuild the State pattern in a very different way. Instead of relying on inheritance, I make the state machine explicit as data and use decorators to define transitions. The result is a small, reusable engine where the entire flow becomes visible at a glance. If you’re interested in writing Python that’s easier to reason about and extend, this is a pattern worth understanding. 👉 Watch here: https://lnkd.in/eg22yEHR. #python #softwaredesign #designpatterns #statemachine #cleancode
To view or add a comment, sign in
-
-
Ever tried to sort a list and ended up with None? The logic looks correct: nums = [3, 1, 2] sorted_nums = nums.sort() print(sorted_nums) 👉 Output: None Why did it fail? In Python, there is a big difference between a Method that modifies an object and a Function that returns a new one. 1️⃣ .sort() is a Method: It modifies the original list "in-place." It doesn't need to return anything because the work is done directly on the original variable. 2️⃣ sorted() is a Function: It creates a brand-new list and leaves the original one exactly as it was. Use .sort() when you want to save memory and don't need the original order anymore. Use sorted() when you need to keep your original data safe and want a new sorted version. #Python #30DaysOfCode #BCA #LearningInPublic #Day22 #JECRC
To view or add a comment, sign in
-
-
Python Dunder Methods: Making code more "Pythonic" 🐍 I’ve been playing around with operator overloading today! Instead of writing a bulky function like add_packages(pkg1, pkg2), Python allows us to use the __add__ magic method. By defining __add__, I can simply use the + operator to combine two package objects. Cleaner syntax? Check. More readable? Absolutely. I also added __str__ to ensure that when I print the result, I get a clear, formatted summary of the dimensions and weight rather than a messy memory address. #Python #CodingTips #SoftwareDevelopment #ObjectOrientedProgramming #CleanCode
To view or add a comment, sign in
-
-
Managing Python environments shouldn’t be a nightmare. But for many — it still is. Here’s how to keep things clean, fast, and production-ready in 2026: 🛠️ Use uv or poetry to manage environments & dependencies. Faster, safer, and simpler than old-school pip+venv. ⚡ Speed matters – use polars, numpy, and numba to vectorize heavy loops. Even small tweaks can give 10× performance wins. 🧼 Lint + Format + Type-check = non-negotiable Ruff for linting Black for formatting Pyright or Pyrefly for fast type-checks 💡 Bonus tip: Use Typer to build CLIs in minutes. So clean, it feels like magic. 💬 What’s one Python setup rule you wish you knew earlier? #Python #CodeQuality #Productivity #DevTools #DataEngineering
To view or add a comment, sign in
-
-
Python Clarity Series – Episode 25 Topic: Mutable vs Immutable Function Behavior 📌 Why did my list change after function call? def modify(lst): lst.append(100) a = [1, 2] modify(a) print(a) Output: [1, 2, 100] 👉 Lists are mutable → changes reflect outside Now: def modify(x): x = x + 10 a = 5 modify(a) print(a) Output: 5 👉 Integers are immutable → no change outside 💡 Rule: Mutable → changes persist Immutable → changes don’t This confusion causes logic errors. #PythonBasics #FunctionConcepts #StudentClarity #python #clarity
To view or add a comment, sign in
-
-
Newsflash: Python is the new Excel. Don't be the only one stuck with 1,048,576 rows. So to avoid this fate, here's a 7-day crash course to help you finally quit the green icon: https://lnkd.in/d7neSJXZ
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
Great insights on control flow! The way Python stops at the first True condition in an if-elif chain is a crucial logic to master. Personally, I use while more for open-ended logic, but for loops feel much safer to avoid those 'terrifying' infinite loops you mentioned. Do you have a favorite trick to debug your indentation errors faster? RITESH KAKADE