11. INDEXING AND SLICING LISTS, BASIC OPERATIONS ON LISTS AND DICTIONARIES, STRING MANIPULATION TECHNIQUES

These free B.Pharm notes on indexing slicing and string manipulation in python cover chapter 11 of Basics of Python Programming for Pharmaceutical Sciences (BP101T), a first-semester subject. Read the key points below, then study the complete chapter PDF. You can browse every chapter in the Basics of Python Programming for Pharmaceutical Sciences category.

Read the following document for full information

Overview of indexing slicing and string manipulation in python

These notes explain positive and negative indexing and the start, stop and step parts of list slicing. They then cover basic operations on lists and dictionaries, string manipulation techniques such as case conversion, strip(), replace(), split(), join(), find() and f-strings, and end with worked pharmacy programs on drug stock lists, prescriptions and drug labels.

Key points on indexing slicing and string manipulation in python

  • Python indexing starts at 0 for the first element, and negative indexing counts backward from the end, so the last element is at -1.
  • Slicing uses the form list[start:stop:step]; the start element is included, the stop element is excluded, and step defaults to 1.
  • Slicing always returns a new list and never changes the original, and a step of -1 produces a reversed copy of the list.
  • Lists use append() and insert() to add items, and remove(), pop() and the del statement to take items out.
  • Strings are ordered, immutable, indexed and iterable, and methods such as upper(), strip(), replace(), split() and find() process text.

Relevance to pharmacy practice

Pharmacy software must pull out particular drug entries, update stock lists and patient prescriptions, and format drug labels clearly. These indexing, slicing and string skills let a pharmacist standardise labels, change dosage information and process prescription text quickly and correctly.

Every chapter in this subject builds on the one before it, so do not skip topics that look simple. Definitions, principles, procedures and examples are the parts that examiners return to most often, and a clear understanding here will also make later subjects easier to follow in the coming semesters.

Frequently asked questions on indexing slicing and string manipulation in python

What is negative indexing in a Python list?

Negative indexing counts positions from the right-hand end of the list, with the last element at -1. It is handy for reaching the last item without knowing the list’s length.

Is the stop index included when slicing a list?

No. Python stops just before the stop index, so the element at that position is left out of the slice, while the element at the start index is included.

What does the find() method return in Python?

The find() method returns the index where a substring first appears in a string, or -1 if the substring is not present at all.

Quick revision checklist

Use this self-test after reading the chapter on indexing slicing and string manipulation in python. If you can do all of the following without looking at your notes, you are ready for the exam.

  • I can explain: positive and negative indexing in lists
  • I can explain: the start, stop and step slice components
  • I can explain: adding, removing and updating list elements
  • I can explain: basic operations on Python dictionaries
  • I can explain: common string methods and f-strings

Study and exam tips

Start by reading the chapter once for the overall idea, then revise indexing slicing and string manipulation in python using headings, definitions, principles, reactions and examples. Short-answer questions in the university exam usually ask for definitions, principles, procedures, reactions and uses, so write these in your own words and practise the equations, tables and flow charts that the chapter has.

For wider reading, standard books and open resources such as the NCBI Bookshelf help you confirm terms and see more examples. Revise indexing slicing and string manipulation in python again a day later and again a week later, because spaced revision improves long-term memory.

This page is part of the Basics of Python Programming for Pharmaceutical Sciences series for first-semester B.Pharm students on B.Pharm Guru, where every chapter has a short summary and a full PDF. Bookmark this page and share it with classmates who are preparing for the same exam.

Related notes: 13. READING AND WRITING CSV FILES, 14. UNDERSTANDING STRUCTURED HEALTHCARE DATASETS.

Next: 12. INTRODUCTION TO NUMPY ARRAYS AND BASIC OPERATIONS USING NUMPY. Back to the Basics of Python Programming for Pharmaceutical Sciences category.