CH - 4 Strings

Introduction to string manipulation and operations

Strings: A “string” is a data type in Python, composed of a collection of characters which can include letters, numbers, and even special characters. For instance, a person’s name, a sentence, can be stored as a string. Working with strings is common in programs that interact with users, like those that display messages or take input.

A few examples of these string methods are as follows

# Suppose we have a test string, say "Assosciation for Computing Machinery"
test_string = "Assosciation for computing machinery"

print(test_string.upper()) # Prints "ASSOSCIATION FOR COMPUTING MACHINERY"
print(test_string.lower()) # Prints "assosciation for computing machinery"
print(test_string.capitalize()) # Prints "Assosciation for computing machinery"
print(test_string.count("s")) # Prints the number of times 's' appears in the string, which is 3 in our case