STRING - NOTES - For (11th Cbse)
STRING - NOTES - For (11th Cbse)
Operation of String
NOTE: Strings are immutable means that the content of the string cannot be changed
Function
Description Code Output
Name
I AM
This function converts str = ” I am Learning Python”
upper() LEARNING
the string into uppercase print(str.upper())
PYTHON
This function converts the str = ” I am Learning Python” i am learning
lower()
string into lowercase print(str.lower()) python
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))
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())
Q3. Write a program to accept a string and display the following:
Number of uppercase characters
Numbers of lowercase characters
Total number of alphabets
Number of digits
str=input("Enter any String")
u=0
L=0
d=0
l = len(str)
for i in range(l):
if str[i].isupper():
u = u+1
if str[i].islower():
L=L+1
if str[i].isdigit():
d = d+1
print("Total Upper Case Characters are: ", u)
print("Total Lower Case Characters are: ", L)
print("Total Characters are: ", L + u)
print("Total digits are: ", d)