✂️The Half-Open Interval Rule in Slicing This rule means the start index is included but the end index is excluded. Look at the following image 👇 According to the rule, the end index 3 is excluded. So the value 7 (at index 3) is not included, and the last value taken is 5. Here, index 1 is the start index, and the value at index 1 is 4. Many popular programming languages follow this rule. Slicing is not the only place where this applies — "for" loops also use this rule behind the scenes. #Python #python #Javascript #javascript #js #Programming #CodingTips #Developer #LearnToCode
Understanding the Half-Open Interval Rule in Slicing
More Relevant Posts
-
🧠 Hoisting - not a programming universal. Look at the following error of two different snippet in attached image👇 In JavaScript, behavior differs based on how variables are declared. Variables declared with var are hoisted and initialized with undefined, so accessing them before declaration does not throw an error. Variables declared with let and const are also hoisted but remain uninitialized in the Temporal Dead Zone, which is why accessing them before declaration throws a ReferenceError. In Python, variable declarations are not hoisted. The interpreter executes code line by line, from top to bottom. When print(message) runs, the variable message has not been created yet, so Python raises a NameError. Shortly: Python binds names only when their definition executes, while js hoists declarations and knows names before execution begin. 👉 Same intent, same flow, same mistake — different outcome due to different working behavior. #programming #Programming #JavaScript #javascript #Python #python #ProgrammingTips #learning #learn #tips
To view or add a comment, sign in
-
-
🐍 Python Conditional Statements — Making Decisions in Code 🌡️ Want your program to react to real situations? Use if-else statements 👇 temperature = 25 if temperature > 22: print("its hot") else: print("its cold") ✅ Output: its hot 💡 How it works: ✔️ if checks the condition ✔️ If TRUE → first block runs ✔️ If FALSE → else block runs 🔥 This is how apps decide things like: • Showing weather alerts • Turning on AC automatically • Sending notifications • Game logic 🚀 Master conditions, and your programs become smart — not just static code. #Python #Coding #Programming #LearnToCode #Developer #100DaysOfCode
To view or add a comment, sign in
-
🐍 Python Nuance: Lists vs Tuples 🐍 Though lists and tuples look similar in Python, they serve different purposes: Lists are mutable — perfect when you need to update or change data. Tuples are immutable — ideal for protecting data from accidental changes. 🛠 Pro tip: If your data won’t change, use a tuple. If it needs to be updated, use a list. Small decisions like this help make your code clearer, safer, and easier to maintain. Happy coding! 🚀 #Python #CleanCode #DeveloperTips #Programming #SoftwareEngineering #Coding #Development #Debugging #Web
To view or add a comment, sign in
-
-
Searching & Sorting Algorithms power almost everything we build - from search features to ranked lists. I just published a complete, practical guide covering: • Linear & Binary Search • Bubble, Merge, Quick Sort • Big-O explained simply • Real-world use cases • Code in Python, JavaScript, Java, C++ & C If you’re preparing for interviews or strengthening your DSA foundation, this will help. 👉 Read here: https://lnkd.in/g2kJhgKc #DSA #Algorithms #Programming #SoftwareDevelopment #Python #JavaScript #Coding
To view or add a comment, sign in
-
-
I love how programming languages end up with unofficial nicknames. C is often called “portable assembly”, JavaScript gets labeled “the language that powers the web and breaks your expectations”, and Python is basically “executable pseudocode.” photo by BabijaPhoto JB: https://lnkd.in/eygq8YKw
To view or add a comment, sign in
-
-
🚀 Beginner Project Alert: Python Basic Calculator I’ve just built a Basic Calculator using Python & Tkinter as part of my journey into GUI development! This project helped me understand: 🔹 Tkinter fundamentals for GUI design 🔹 Event handling & button commands 🔹 Using eval() for expression calculation 🔹 Structuring a simple Python application It may be a beginner-level project, but it’s a strong step toward building more advanced desktop applications. 💻✨ Every expert was once a beginner — and this is one of my building blocks! I’d love your feedback: 👉 What feature should I add next? (Scientific functions, history, better UI?) GitHub Repo Link: https://lnkd.in/dd6yUT6u #Python #Tkinter #BeginnerProject #CodingJourney #PythonProjects #WomenInTech
To view or add a comment, sign in
-
-
Ever puzzled by OOP vs POP? Functions or classes—which rules? My latest blog breaks it down: from procedural C snippets to OOP power in Python/Java/C++. See the difference between oop pop with real code, tables, and a bank app example. Perfect for beginners or interview prep! Dive in: https://lnkd.in/gDNDw3hW #OOP #POP #Programming #CodingTips #CPlusPlus #Python #Java #TechBlog #analyticsjobs
To view or add a comment, sign in
-
-
Python is a good example of underrated language that can blend fp with oop. You can design state using object oriented features but for god sakes, please don’t use inheritance more than 2 level. Then in the method, you define all state transforming operations using functional programming. I am using it now to reimplement redis in Python and start to enjoy writing code again.
To view or add a comment, sign in
-
🐍 Python (3.8+) Walrus Operator (:=) Filtering + using a value is something we all do very often. One search. One condition. One clear intent. 🧠 Mental shortcut 👉 Get the value → check it → use it. Perfect for: • Regex • Lookups • Optional returns • Guard clauses This is not a trick. This is readability with discipline. #Python #CleanCode #Developer #Programming #SoftwareEngineering
To view or add a comment, sign in
-
-
Another Python edge case I ran into while adding support in Memphis: generator return values. The return value doesn't show up in iteration (like the `list()` builtin), but it is surfaced via `StopIteration` when you advance the generator directly (using the `next()` builtin). A short example is below. I can't say I've ever encountered this as a user, but it was a fun one to discover while implementing it.
To view or add a comment, sign in
-
More from this author
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
This rule confused me when I first learned slicing. Did it confuse you too?