Python Strings and Built-in Functions – Detailed
Notes
Python strings are sequences of characters used to store and manipulate text. Strings are
immutable, meaning they cannot be changed after they are created.
Strings can be written using single quotes ('text'), double quotes ("text"), or triple quotes for multiline
text.
Important properties of strings include indexing, slicing, and immutability.
Function Purpose Example
upper() Convert string to uppercase 'python'.upper() → PYTHON
lower() Convert string to lowercase 'HELLO'.lower() → hello
capitalize() Capitalize first letter 'python'.capitalize() → Python
title() Capitalize each word 'python language'.title()
strip() Remove spaces from ends ' hello '.strip()
replace() Replace part of string 'I like Java'.replace('Java','Python')
split() Split string into list 'Python is easy'.split()
join() Join list elements into string ' '.join(['Python','is','fun'])
find() Find index of substring 'python'.find('p')
count() Count occurrences 'banana'.count('a')
startswith() Check starting text 'Python'.startswith('Py')
endswith() Check ending text '[Link]'.endswith('.pdf')
isalpha() Check if letters only 'Python'.isalpha()
isdigit() Check if digits only '12345'.isdigit()
isalnum() Check letters or digits 'Python123'.isalnum()
len() Length of string len('Python')