Python for Placements7 min Read

Placement Prep 2026: Python List Indexing & Slicing for TCS NQT, Infosys SP, & Google SDE-1

By DevLingo Team • Published

Namaste, future coding rockstars!

Now that you are acquainted with lists, it is time to learn a little bit more about them. Today's module, **Python Module Four Part Two: Indexing**, dives deep into a fundamental concept that's absolutely critical for anyone aiming for top tech placements. Think TCS NQT, Infosys SP, or even cracking the Google India SDE-1 interview — mastering list indexing and slicing is your stepping stone. This isn't just theory; it's a practical skill that sets you apart for high-paying roles, especially in buzzing tech hubs like Bangalore and Hyderabad, where ₹12LPA+ salaries are becoming the new benchmark for freshers.

Unlocking Data: What is Python List Indexing?

Imagine you have a shopping list, but it’s super long. How do you find a specific item quickly? You’d look at its position. In Python, lists are ordered collections, and **indexing** is how we access individual elements based on their position. Each element in a list is assigned a unique index, making it incredibly powerful for data manipulation.

The Basics: Positive Indexing

Python lists use **0-based indexing**. This means the first element is at index `0`, the second at `1`, and so on. It’s a common starting point in many programming languages, so get comfortable with it!

**Example:** ```python my_list = ['DevLingo', 'Python', 'Placement', 'Prep', '2026']

print(my_list[0]) # Output: DevLingo print(my_list[2]) # Output: Placement ```

Going Backwards: Negative Indexing

Python also offers **negative indexing**, which allows you to access elements from the end of the list. The last element is at index `-1`, the second to last at `-2`, and so forth. This is incredibly handy for quick access to the end of a list without knowing its exact length.

**Example:** ```python my_list = ['DevLingo', 'Python', 'Placement', 'Prep', '2026']

print(my_list[-1]) # Output: 2026 print(my_list[-3]) # Output: Placement ```

Beyond Single Elements: Python List Slicing

While indexing gets you a single element, **slicing** allows you to extract a *sub-section* or a *sub-list* from your main list. This is where the real power of list manipulation comes in, crucial for algorithms you'll encounter in coding rounds for companies like Google or top startups.

Basic Slicing: `[start:end]`

The syntax for basic slicing is `list[start:end]`. This returns a new list containing elements from the `start` index up to (but *not including*) the `end` index.

  • If `start` is omitted, it defaults to `0`.
  • If `end` is omitted, it defaults to the end of the list.

**Example:** ```python placement_topics = ['Arrays', 'Strings', 'Lists', 'Dicts', 'Trees', 'Graphs', 'DP']

print(placement_topics[1:4]) # Output: ['Strings', 'Lists', 'Dicts'] print(placement_topics[:3]) # Output: ['Arrays', 'Strings', 'Lists'] print(placement_topics[4:]) # Output: ['Trees', 'Graphs', 'DP'] print(placement_topics[:]) # Output: ['Arrays', 'Strings', 'Lists', 'Dicts', 'Trees', 'Graphs', 'DP'] (A copy of the list) ```

Advanced Slicing: `[start:end:step]`

Want to skip elements? The `step` parameter comes to your rescue! It defines the increment between elements in your slice.

  • A positive `step` skips elements forward.
  • A negative `step` reverses the order and allows for interesting manipulations.

**Example:** ```python numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

print(numbers[::2]) # Output: [0, 2, 4, 6, 8] (Every other element) print(numbers[1:8:3]) # Output: [1, 4, 7] print(numbers[::-1]) # Output: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] (Reverse the list – super useful for interviews!) ```

Real-World & Interview Applications

Mastering indexing and slicing isn't just for theoretical understanding; it's a direct route to efficient problem-solving in coding challenges:

  • **Data Cleaning:** Extracting specific date ranges from logs or user data.
  • **Feature Engineering:** Creating new features from existing data by slicing relevant parts.
  • **Algorithm Implementations:** Reversing strings, checking for palindromes, extracting sub-arrays in dynamic programming problems. These are common in TCS NQT and Infosys SP coding rounds.
  • **Competitive Programming:** Quickly manipulating data structures for optimal solutions.

Companies in Bangalore and Hyderabad, from established giants to fast-growing startups, value candidates who can write clean, efficient Python code. Your ability to wield indexing and slicing expertly reflects a strong grasp of Python fundamentals – a non-negotiable for a ₹12LPA+ SDE role.

Your Path to a ₹12LPA+ Job: Practice Makes Perfect!

Don't just read this; *do* this! The more you practice list indexing and slicing, the more intuitive it becomes. This fundamental skill is tested in various forms across entry-level interviews. Whether it's a simple selection in TCS NQT or a complex data manipulation task in a Google SDE-1 technical round, a strong command over Python lists is your secret weapon.

Head over to DevLingo's practice platform to tackle challenges that involve manipulating lists, extracting sub-lists, and reversing sequences. Your dream job at a top Bangalore or Hyderabad startup, with a rewarding salary package, is just a few practice problems away. Keep coding, keep growing!

Frequently Asked Questions

How does Python list indexing/slicing appear in coding interviews like TCS NQT or Infosys SP?

In TCS NQT, Infosys SP, and similar freshers' interviews, indexing and slicing are frequently tested implicitly. You might be asked to reverse a list or string, extract a sub-array that meets certain conditions, or perform operations on specific parts of a list. For instance, a problem requiring you to process only the last 'k' elements of a list would directly use negative indexing or slicing. Efficiency matters, and correct usage of slicing can often provide a concise and performant solution.

What are common mistakes freshers make when using indexing and slicing in Python lists?

Common mistakes include 'IndexError: list index out of range' when trying to access an element beyond the list's bounds (e.g., `my_list[len(my_list)]` instead of `my_list[len(my_list)-1]`). For slicing, a frequent oversight is forgetting that the `end` index is *exclusive* (the element at `end` is not included). Also, confusing positive and negative indexing, or not understanding how the `step` parameter works (especially with negative steps for reversal), are typical pitfalls. Always remember to practice edge cases like empty lists or lists with single elements.

🦊

Ready to stop scrolling and start coding?

Everything you just read is built into DevLingo as a playable challenge. Don't just learn it. **Own it.**

Download QR
Scan to Download