CS - String Manipulation in Python
CS - String Manipulation in Python
Strings in Python
St[1] = Y St[5] = N St[-1] = N St[-6] = P
Iterating through string using for loop:
Strings in Python
Strings in
Python
print(„W‟ in str1)
print(„Wel‟ not in str1)
Strings in Python
NOTE: Strings are immutable means that the content of the string cannot be changed
CS (083) HOLY CROSS SCHOOL, HAZARIBAG KHALID IQBAL
alphanumeric
characters str=”IamLearningPython” True
only. If there is one print(str.isalnum())
space in a string,
this function will
return False.
False(#contain upper
str=”I am Learning Python”
case alphabet)
This function returns print(str.islower())
True if all the
islower() characters
in the string are in
lower case str=”i am learning python”
print(str.islower())
True
False
str=”I am Learning Python”
print(str.isspace())
This function returns
True if all the str=” “
isspace() True (#contain only
characters in the print(str.isspace())
space)
string is whitespace.
str = “”
print(str.isspace())
False
Practice Questions
Q1. Write a program to count the frequency of a character in a string.
str=input("Enter any String")
ch=input("Enter the character")
print(str.count(ch))
CS (083) HOLY CROSS SCHOOL, HAZARIBAG KHALID IQBAL
Q2. Write a program to accept a string and return a string having first letter of each word in capital.
str=input("Enter any String")
print(str.title())