๐Ÿ“Strings: Methods, Slicing, IndexingLESSON

Strings: Methods, Slicing, Indexing

Strings are one of the most-used types in Python. They're sequences of Unicode characters, which means you can index them, slice them, and iterate over them just like lists.

Creating Strings

Indexing

Strings are zero-indexed. Use [index] to access individual characters:

Slicing

Slicing extracts a substring using [start:stop:step]:

String Immutability

Strings cannot be changed in place. Every string "modification" creates a new string:

len() and the in Operator

Essential String Methods

Python's string methods return new strings โ€” they never modify the original.

Case Methods

Whitespace Methods

Search Methods

Split and Join

Replace

Alignment and Padding

Testing Methods

Chaining Methods

Because methods return new strings, you can chain them:

String Multiplication

Knowledge Check

What does "Hello"[-1] return?

What does "hello world".split() return?

What does "-".join(["a", "b", "c"]) return?