🚀 Day 4 of #14DaysOfPython 🐍 Today’s focus: Strings (Core Concepts) — working with text in Python. 💡 Easy way to understand strings: 🔹 Why strings? 👉 Almost every real-world program deals with text (names, inputs, data processing) 💡 Core Concepts (Logic First): 🔹 String Indexing & Slicing 👉 Access characters using position s[0] → first character s[-1] → last character s[start:end] → substring 🔹 String Traversal 👉 Loop through characters for loop → simple iteration while loop → more control 🔹 Built-in Methods 👉 Modify strings easily lower(), upper() → case change strip() → remove spaces replace() → replace characters 🔹 ASCII Basics 👉 Convert between characters and numbers ord('A') → 65 chr(65) → 'A' 🧠 Problems I practiced: Palindrome check Reverse a string Count vowels & consonants Remove spaces from a string ✨ Key takeaway: Strings are not just text — they are data you can manipulate step-by-step using logic. Day 4 done ✅ Moving to Day 5 💪 #HackerRank #Python #ProblemSolving #CodingJourney #Developer #LearningInPublic #codegnan
Python Strings Core Concepts and Methods
More Relevant Posts
-
🔤 DAY 2/30: I CAN NOW MANIPULATE TEXT LIKE A PRO Today I learned string methods in Python - functions that transform text. 📚 WHAT I LEARNED: • .strip() - remove extra spaces (clean user input) • .upper() / .lower() - change case instantly • String slicing - grab specific parts of text [start:end] • .replace() - swap words in seconds 🛠️ PROJECT: Username Validator A program that: 1. Takes any messy username input 2. Cleans it (removes spaces, fixes case) 3. Validates length (5-15 characters) 4. Tells you if it's available 💡 BIGGEST INSIGHT: String methods don't change the original - they create a NEW string. That's why you need to save them: `name = name.strip()` 🐛 BUG I FIXED: Forgot to save the cleaned string - kept getting original. Now I know: methods RETURN values, they don't modify in place. 📂 DAY 2 CODE: https://lnkd.in/gvg2Rh6N 28 days to go. Getting stronger every day. #Python #30DaysOfCode #CodingJourney #LearnToCode
To view or add a comment, sign in
-
Day 11/365: Finding the Smallest & Second Smallest Element in a List 🔍📉 Today I worked on a classic list problem in Python: finding the smallest and second smallest elements in a list, along with their indexes — without sorting the list. What this code does step by step: I start with a list L containing different numbers. I initialize two variables: smallest and s_smallest (second smallest) with a value larger than most of the elements in the list. I also track their positions using smallest_index and second_smallest_index. Then I loop through the list using indexes: If the current element is less than or equal to smallest, I: move the current smallest to s_smallest, update smallest with the new value, and update both indexes accordingly. Else if the current element is only smaller than s_smallest, I update just the second smallest and its index. In the end, I print both the smallest and second smallest values with their positions in the list. What I learned from this exercise: How to track not just one, but two minimum values in a single pass through the list. How important it is to maintain both the value and the index while updating. How careful initialization of variables (like smallest and s_smallest) affects the correctness of the logic. How this pattern can be extended to find top-k smallest or largest elements efficiently without sorting. Day 11 done ✅ 354 more to go. If you have ideas like handling edge cases (e.g., duplicates, negative numbers, very large lists) or finding the k-th smallest element, send them my way — I’d love to build on this next. #100DaysOfCode #365DaysOfCode #Python #LogicBuilding #Lists #Indexing #CodingJourney #LearnInPublic #AspiringDeveloper
To view or add a comment, sign in
-
-
Unlocking the Power of Strings in Python! 🐍✨ Today’s focus on my Python journey was all about understanding and manipulation—specifically, Strings. It’s incredible how much logic depends on effectively handling text data! Here are my key takeaways from today's deep dive: ✂️ String Slicing: Mastering the [start:stop:step] syntax. It feels like precision surgery for text data—extracting exactly what you need, whether it's a prefix, a suffix, or a reversed substring. 🚫 String Immutability (Mutation): A crucial realization! You can’t change a string in place. Trying to do word[0] = 'C' will throw an error. Understanding this forces you to think correctly about creating new modified strings instead of trying to mutate existing ones. 🛠️ String Methods: My toolbox just got a lot bigger. I explored powerful built-in functions like: .strip() for cleaning up whitespace. .replace() for quick swaps. .split() and .join() for converting between strings and lists. .upper(), .lower(), .capitalize() for formatting. Understanding these fundamentals is making my code cleaner and more efficient. Every day is a step closer to building complex applications! #Python #CodingJourney #Strings #DataManipulation #SoftwareDevelopment #ContinuousLearning #WebDev #Backend #ProgrammingFundamentals #CleanCode #LearningToCode
To view or add a comment, sign in
-
-
There is something very powerful in Python that you can unlock by implementing just 2 methods. __𝙡𝙚𝙣__ __𝙜𝙚𝙩𝙞𝙩𝙚𝙢__ For example, if you implement this: 𝗰𝗹𝗮𝘀𝘀 𝗗𝗲𝗰𝗸: 𝗱𝗲𝗳 __𝗶𝗻𝗶𝘁__(𝘀𝗲𝗹𝗳, 𝗰𝗮𝗿𝗱𝘀): 𝘀𝗲𝗹𝗳.𝗰𝗮𝗿𝗱𝘀 = 𝗰𝗮𝗿𝗱𝘀 𝗱𝗲𝗳 __𝗹𝗲𝗻__(𝘀𝗲𝗹𝗳): 𝗿𝗲𝘁𝘂𝗿𝗻 𝗹𝗲𝗻(𝘀𝗲𝗹𝗳.𝗰𝗮𝗿𝗱𝘀) 𝗱𝗲𝗳 __𝗴𝗲𝘁𝗶𝘁𝗲𝗺__(𝘀𝗲𝗹𝗳, 𝗽𝗼𝘀𝗶𝘁𝗶𝗼𝗻): 𝗿𝗲𝘁𝘂𝗿𝗻 𝘀𝗲𝗹𝗳.𝗰𝗮𝗿𝗱𝘀[𝗽𝗼𝘀𝗶𝘁𝗶𝗼𝗻] Your object automatically supports: • 𝗹𝗲𝗻(𝘥𝘦𝘤𝘬) • 𝘥𝘦𝘤𝘬[0] • slicing → 𝘥𝘦𝘤𝘬[:3] • iteration → 𝗳𝗼𝗿 𝘤𝘢𝘳𝘥 𝗶𝗻 𝘥𝘦𝘤𝘬 • 𝗶𝗻 operator • 𝗿𝗮𝗻𝗱𝗼𝗺.𝗰𝗵𝗼𝗶𝗰𝗲(𝘥𝘦𝘤𝘬) • 𝘀𝗼𝗿𝘁𝗲𝗱(𝘥𝘦𝘤𝘬) You didn’t implement: • iteration • slicing • search • random selection Python gave you all of that. That takeaway is: If your object behaves like a sequence, Implement __𝗹𝗲𝗻__ + __𝗴𝗲𝘁𝗶𝘁𝗲𝗺__ and let Python do the rest. Don’t build features. Plug into the Data Model. #python #datamodel #dunder #magicmethods #__len__ #__getitem__
To view or add a comment, sign in
-
Day 2 of my LeetCode journey 🚀 Today’s problem: Group Anagrams This challenge was all about grouping strings that share the same characters. I approached it using a dictionary + hashing strategy in Python. For each word, I sorted its characters and used that as a key (converted into a tuple), ensuring all anagrams map to the same bucket. Here’s the core logic I implemented: ▪️Traverse the list of strings ▪️Sort each string → convert to tuple → use as dictionary key ▪️Append original string to the corresponding group ▪️Finally, return all grouped values This approach keeps the implementation clean and scalable. Time Complexity: ▪️Sorting each string takes O(k log k) (where k = length of string) ▪️For n strings → O(n * k log k) overall Space Complexity: ▪️O(n * k) for storing grouped anagrams A solid step forward in understanding how hashing + transformations can simplify complex grouping problems. Staying consistent and leveling up daily 💪 #LeetCode #Day2 #Python #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚨 This behavior of Python might look like a BUG… but it isn’t actually. a = 10 b = 10 print(id(a)) print(id(b)) 👉 Same memory location 😲 “Why do we have two variables pointing to the same memory location?!” Here comes the second one and things get interesting 👇 a = [1, 2, 3] b = a b.append(4) print(a) # [1, 2, 3, 4] 🔥 👉 Hmmm… why did ‘a’ change?! 💡 Explanation: ⭐ id() returns the identity of an object ⭐ Python reuses memory locations for immutable values ⭐ For mutable objects however, there is no copying, just pointers! ⚠️ The misconception: Most people believe ‘=’ copies objects in variables. 👉 Nope! ✅ Solution: b = a.copy() Now the two variables are separate ✅ 🔥 Consequence: It can seriously mess up your program’s logic! Ever got caught by such a ghost bug in Python? 👇 #CodeWithSujith #Python #Programming #Coding #PythonTricks #LearnPython #PythonBeginner #100DaysOfCode #DeveloperJourney
To view or add a comment, sign in
-
-
🚀 Day 19/60 – Iterators (Understand How Python Loops Work Internally ⚡) Yesterday you learned Decorators. Today, let’s go deeper into how Python actually loops 👇 🧠 What is an Iterator? An iterator is an object that lets you loop through data one item at a time. 👉 Implements __iter__() and __next__() 👉 Used behind every for loop 🔄 How for loop works internally numbers = [1, 2, 3] iterator = iter(numbers) print(next(iterator)) # 1 print(next(iterator)) # 2 print(next(iterator)) # 3 👉 StopIteration is raised at the end ⚡ Custom Iterator class CountUp: def __init__(self, max): self.max = max self.current = 1 def __iter__(self): return self def __next__(self): if self.current > self.max: raise StopIteration val = self.current self.current += 1 return val for num in CountUp(5): print(num) 🔍 Iterator vs Iterable 👉 Iterable → Object you can loop over (list, tuple, string) 👉 Iterator → Object that actually produces values 🔥 Why Iterators Matter? ✅ Memory efficient ✅ Lazy evaluation ✅ Core of generators ❌ Common Mistake Confusing iterable with iterator ❌ 👉 Not every iterable is an iterator 🔥 Pro Tip 👉 Use iter() to convert iterable → iterator 👉 Use next() to manually fetch values 🔥 Challenge for today 👉 Create a custom iterator 👉 That returns numbers from 1 to 3 👉 Use next() manually Comment “DONE” when finished ✅ Follow Adeel Sajjad to stay consistent for 60 days 🚀 #Python #PythonProgramming #LearnPython #Coding #Programming #Developer
To view or add a comment, sign in
-
-
🚀 Day 3/30 of My LeetCode Journey (Python + SQL) Showing up daily and building consistency, one problem at a time! 💻🔥 🔹 **Python Problems of the Day** 👉 *1. Move Zeroes* Given an integer array, move all 0’s to the end while maintaining the relative order of non-zero elements. Do it in-place without making a copy. 💡 *Key Concept:* Two-pointer technique for efficient in-place rearrangement. 👉 *2. Remove Element* Given an array and a value, remove all occurrences of that value in-place and return the number of remaining elements. 💡 *Key Concept:* In-place filtering using pointer overwrite approach. 🔹 **SQL Problem of the Day** 👉 *Find Duplicate Emails* Given a `Person` table with an email column, write a query to report all duplicate emails. 💡 *Key Concept:* GROUP BY with HAVING COUNT > 1. Small steps daily = Big progress over time 📈 Staying consistent and enjoying the process! #LeetCode #30DaysChallenge #Python #SQL #CodingJourney #Consistency #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
Clean code isn't clever. It's clear. 5 Python patterns every developer should know: 1️⃣ Flatten nested list: flat = [x for sub in nested for x in sub] 2️⃣ Merge dicts (Python 3.9+): merged = dict_a | dict_b 3️⃣ Most frequent item: max(set(lst), key=lst.count) 4️⃣ Swap variables: a, b = b, a 5️⃣ Read + strip file lines: lines = [l.strip() for l in open("file.txt")] --------------- These aren't tricks. They're idiomatic Python. When your code communicates intent: ✅ Reviews go faster ✅ Bugs surface sooner ✅ Onboarding is smoother Write for the developer reading it at 2am before a deployment. That developer is usually you. #Python #CleanCode #Programming #CodingTips #SoftwareEngineering
To view or add a comment, sign in
-
-
🧠 Python Concept: strip(), lstrip(), rstrip() Clean your strings like a pro 😎 ❌ Problem text = " Hello Python " print(text) 👉 Output: " Hello Python " 😵💫 (extra spaces) ❌ Traditional Way text = " Hello Python " text = text.replace(" ", "") print(text) 👉 Removes ALL spaces ❌ (not correct) ✅ Pythonic Way text = " Hello Python " print(text.strip()) # both sides print(text.lstrip()) # left only print(text.rstrip()) # right only 🧒 Simple Explanation Think of it like cleaning dust 🧹 ➡️ strip() → clean both sides ➡️ lstrip() → clean left ➡️ rstrip() → clean right 💡 Why This Matters ✔ Clean user input ✔ Avoid bugs in comparisons ✔ Very useful in real-world apps ✔ Cleaner string handling ⚡ Bonus Example text = "---Python---" print(text.strip("-")) 👉 Output: "Python" 🐍 Clean data, clean code 🐍 Small functions, big impact #Python #PythonTips #CleanCode #LearnPython #Programming #DeveloperLife #100DaysOfCode
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