Strings and String manipulation - Formula Sheet
Key String Operations and Syntaxes
Here is a quick reference of the syntax rules and operators used for string manipulation in Python:
| Operation | Syntax / Formula | Description |
|---|---|---|
| Basic Slicing | string[start:stop] | Extracts a substring starting at index start up to but excluding the index stop. |
| Slicing with Stride | string[start:stop:stride] | Extracts a substring where stride defines the step size or spacing between characters. |
| Concatenation | string1 + string2 | Combines two or more strings into a single contiguous string. |
| Repetition | string * n | Repeats the specified string n times consecutively. |
| String Formatting | "template %type" % value | Replaces format specifiers like %s (string), %d (integer), or %f (float) with corresponding variables. |
| Format Method | "text {} {}".format(val1, val2) | Dynamically substitutes curly brace placeholders with the provided arguments in order. |
More for this chapter
Book Back Questions10 textbook MCQs · solved
Additional MCQs15 extra MCQs · solved
Practice TestInteractive · instant score
Book Back TestTest yourself on the textbook set
Additional MCQ TestTest yourself on the extra set
Study NotesConcepts & methods
More chapters in Computer Science
View all
1 Function
2 Data Abstraction
3 Scoping
4 Algorithmic Strategies
5 Python -Variables and Operators
6 Control Structures
7 Python functions
9 Lists, Tuples, Sets and Dictionary
10 Python Classes and objects
11 Database Concepts
12 Structured Query Language (SQL)
13 Python and CSV files
14 Importing C++ programs in Python.
15 Data manipulation through SQL
16 Data visualization using pyplot: line chart, pie chart and bar chart