STRING
MANIPULATION
String Manipulation
• Understanding strings in Python
• Common operations and functions
• Overview of string usage in programming
What is a String?
• A string is a sequence of characters
• Strings are immutable
• Declared using single or double quotes
String Creation
Examples:
name = 'Lokesh'
message = "Welcome to Python"
String Indexing
• Positive indexing: 0, 1, 2...
• Negative indexing: -1, -2...
Examples:
s = 'Python'
s[0] → 'P'
s[-1] → 'n'
String Slicing
Syntax: string[start:end]
Examples:
s = 'Learning'
s[0:4] → 'Lear'
s[2:] → 'arning'
Basic String Functions
Function Description
len() Returns length of string
lower() Converts string to lowercase
upper() Converts string to uppercase
title() Converts to title case
capitalize() Capitalizes first character
swapcase() Swaps case of all characters
Search & Check Functions
Function Description
find() Returns index of substring
rfind() Finds substring from right
startswith() Checks start of string
endswith() Checks end of string
count() Counts occurrences
index() Returns index (throws error if not
found)
Modification Functions
Function Description
replace() Replaces substring
strip() Removes spaces from both sides
lstrip() Removes left-side spaces
rstrip() Removes right-side spaces
split() Splits into list
join() Joins list into string
Character Type Checking
(Boolean)
Function Description
isalnum() Checks alphanumeric characters
isalpha() Checks alphabetic characters
isdigit() Checks digits
islower() Checks lowercase
isupper() Checks uppercase
isspace() Checks spaces only