Bharani Park Matric Hr Sec School
Computer Science – Python String Functions (Notes)
isalnum()
Use: Checks if string contains only letters and numbers
Example: 'SaveEarth'.isalnum() → True
isalpha()
Use: Checks if string contains only letters
Example: 'Python'.isalpha() → True
isdigit()
Use: Checks if string contains only digits
Example: '1234'.isdigit() → True
lower()
Use: Converts string to lowercase
Example: 'HELLO'.lower() → hello
islower()
Use: Checks if string is lowercase
Example: 'hello'.islower() → True
isupper()
Use: Checks if string is uppercase
Example: 'HELLO'.isupper() → True
upper()
Use: Converts string to uppercase
Example: 'hello'.upper() → HELLO
title()
Use: Converts first letter of each word to capital
Example: 'education department'.title() → Education Department
swapcase()
Use: Swaps uppercase to lowercase and vice versa
Example: 'TaMiL'.swapcase() → tAmIl
len()
Use: Returns length of string
Example: len('Python') → 6
capitalize()
Use: Capitalizes first letter
Example: 'chennai'.capitalize() → Chennai
center()
Use: Centers string with given width
Example: 'Welcome'.center(15,'*') → ****Welcome****
find()
Use: Finds index of substring
Example: 'mammals'.find('ma') → 0
count()
Use: Counts occurrences of substring
Example: 'banana'.count('a') → 3
ord()
Use: Returns ASCII value of character
Example: ord('A') → 65
chr()
Use: Returns character from ASCII value
Example: chr(65) → A
in operator
Use: Checks if substring is present
Example: 'city' in 'chennai city' → True