Creating strings, indexing, slicing in python
1. Creating Strings
Strings can be created by simply enclosing text within quotes:
2. Indexing
In Python, each character in a string has an index, starting from 0. You can access a specific character by its index.
- Positive indexing starts from the beginning (0, 1, 2, …).
- Negative indexing starts from the end (-1, -2, -3, …).
3. Slicing
Slicing allows you to access a substring or portion of a string by specifying a range of indices.
Tips for Slicing
- start is the beginning index (inclusive).
- stop is the ending index (exclusive).
- step is the interval (or jump) between indices; the default is
1
. Negative steps reverse the slice.