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
More Relevant Posts
-
🚀 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
-
-
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
-
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 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
-
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
-
🧠 Python Concept: enumerate() vs range(len()) Stop writing unnecessary indexing 😵💫 ❌ Traditional Way fruits = ["apple", "banana", "cherry"] for i in range(len(fruits)): print(i, fruits[i]) ❌ Problem 👉 Harder to read 👉 Error-prone 👉 Not Pythonic ✅ Pythonic Way fruits = ["apple", "banana", "cherry"] for index, fruit in enumerate(fruits): print(index, fruit) 🧒 Simple Explanation Think of enumerate() as a smart counter ➡️ Gives index automatically ➡️ No manual tracking ➡️ Cleaner loop 💡 Why This Matters ✔ Better readability ✔ Avoids index bugs ✔ Cleaner & shorter code ✔ Used everywhere in Python ⚡ Bonus Example for i, fruit in enumerate(fruits, start=1): print(i, fruit) 🐍 Don’t count manually 🐍 Let Python do it for you #Python #PythonTips #CleanCode #LearnPython #Programming #DeveloperLife #100DaysOfCode
To view or add a comment, sign in
-
-
Today I explored some important concepts in NumPy, I learned 👇 1. Arrays NumPy arrays are lists of numbers used for fast mathematical operations. Example: Python import numpy as np arr = np.array([1, 2, 3]) 🔹 2. Broadcasting Broadcasting means applying one value to all elements in the array automatically. Example: Python np.array([1,2,3]) + 5 # → [6 7 8] 🔹 3. Axis Axis tells which direction an operation runs. axis=0 → column-wise axis=1 → row-wise Example: Python arr.sum(axis=0) 🔹 4. Slicing Slicing means cutting a part of an array. Example: Python arr = np.array([10,20,30,40]) arr[1:3] # → [20 30] 🔹 5. Stacking Stacking means joining arrays. Example: Python np.hstack((a, b)) np.vstack((a, b)) 🔹 6. Random Values NumPy can create random numbers easily. Example: Python np.random.rand(2,3) 🔹 7. Reshape Reshape changes the shape of an array without changing data. Example: Python np.arange(6).reshape(2,3) # → [[0 1 2] # [3 4 5]]
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
-
-
🚀 Solved another problem on LeetCode: Concatenation of Array Today I worked on a simple yet important array problem that focuses on understanding how data structures behave in Python. Problem Summary: Given an integer array "nums", create a new array "ans" such that: 👉 "ans = nums + nums" (i.e., the array is repeated twice) 💡 My Approach: I used Python’s built-in list concatenation: "return nums + nums" ⚡ Why this approach is best? - No loops required - Clean and readable code - Uses optimized internal operations 📊 Complexity Analysis: • Time Complexity: O(n) • Space Complexity: O(n) 🔁 Comparison with other approaches: 🔸 Using loops → More lines of code, less readable 🔸 Using append() → Slightly slower due to repeated operations 🔸 Using list comprehension → Still less direct My approach is the most efficient and pythonic way to solve this problem. 🧠Key Learning: Sometimes the simplest solution is the most powerful. Knowing built-in operations can save time and improve code quality. Consistency in DSA is the key 🔥 #LeetCode #DSA #Python #CodingJourney #ProblemSolving #Code
To view or add a comment, sign in
-
-
🔍 Python’s Name Mangling: What It Is and When to Use It Ever wondered what happens when you use double underscores (__) in Python class attributes? It’s not just a naming convention—it’s a feature called name mangling, and it’s designed to prevent naming conflicts in inheritance. What Is Name Mangling? When you define an attribute like __private_var inside a class, Python internally renames it to _ClassName__private_var. This ensures that subclasses can’t accidentally override the parent class’s private attributes. Example: class Parent: def __init__(self): self.__value = 42 # Mangled to _Parent__value class Child(Parent): def __init__(self): super().__init__() self.__value = 100 # Mangled to _Child__value obj = Child() print(obj._Parent__value) # Output: 42 print(obj._Child__value) # Output: 100 Both __value attributes coexist without conflict! Why Use Name Mangling? ✅ Avoids naming conflicts in class hierarchies. ✅ Encourages encapsulation by making it harder to accidentally override private attributes. ⚠️ Not true privacy: You can still access mangled names using _ClassName__attribute. When to Use It? Rarely needed: Python encourages convention over enforcement. Use a single underscore (_var) for "private" attributes unless you specifically need name mangling. Use case: When you want to **prevent accidental attribute overridin
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