String processing refers to the operations performed on strings that allow them to be accessed, analyzed, and updated.
String Traversal
The characters in a string can be easily traversed, without the use of an explicit index variable, using the for chr in string form of the for statement
text = "I have a pet cat and a pet dog."
count_a = 0
for char in text:
if char == 'a':
count_a += 1
print("The number of 'a' letters is:", count_a) #The number of 'a' letters is: 4
String-Applicable Sequence Operations
Strings are immutable, so sequence-modifying operations return a new string that is a modified version of the original. Some sequence operations include:
![](https://bscbcanotes.wordpress.com/wp-content/uploads/2024/05/image-96.png?w=1024)
Example operations for s = 'Hello Goodbye!'
:
![](https://bscbcanotes.wordpress.com/wp-content/uploads/2024/05/image-97.png?w=1024)
String Methods
![](https://bscbcanotes.wordpress.com/wp-content/uploads/2024/05/image-98.png?w=916)