Class 11 Informatics Practices – String Topic Notes
1. Introduction to Strings
A string is a sequence of characters enclosed in single quotes (' ') or double quotes (" "). Strings are
immutable in Python, meaning once created, their content cannot be changed.
2. Creating Strings
Strings can be created in the following ways:
1 Single-quoted string: 'Hello'
2 Double-quoted string: "Hello"
3 Triple-quoted string (for multi-line text): '''Hello''' or """Hello"""
3. Accessing Characters and Indexing
Each character in a string has an index. Indexing starts from 0 for the first character and -1 for the
last character.
Example: s = 'Python' → s[0] = 'P', s[-1] = 'n'
4. String Slicing
Slicing allows accessing a portion of the string using the syntax: s[start:end:step]
Example: s = 'Python' → s[1:4] = 'yth'
5. String Operators
1 Concatenation (+): 'Hello' + 'World' → 'HelloWorld'
2 Repetition (*): 'Hi' * 3 → 'HiHiHi'
3 Membership (in / not in): 'a' in 'apple' → True
6. Common String Functions
1 len(s) – Returns the length of the string
2 lower() / upper() – Converts string to lower/upper case
3 title() – Converts the first character of each word to uppercase
4 capitalize() – Capitalizes the first character
5 strip() – Removes leading and trailing spaces
6 replace(old, new) – Replaces a substring with another
7 find(sub) – Returns the index of the first occurrence of sub
8 count(sub) – Counts occurrences of a substring
9 split() – Splits a string into a list
10 join(list) – Joins list elements into a single string
7. String Testing Methods
1 isalpha() – Returns True if all characters are alphabets
2 isdigit() – Returns True if all characters are digits
3 isalnum() – Returns True if string has only alphabets and digits
4 isspace() – Returns True if string contains only spaces
8. Traversing Strings
We can use loops to traverse through a string.
Example:
for ch in 'Python':
print(ch)
9. String Immutability
Strings in Python are immutable. This means you cannot modify a string directly after creation. Any
operation that changes a string actually creates a new string.
10. Common String Programs
1 Program to count vowels in a string
2 Program to check palindrome string
3 Program to reverse a string
4 Program to count frequency of each character