Exercise Questions-String 231001 212451
Exercise Questions-String 231001 212451
1 Mark Questions
Q.No Question
1. print the string “India” 10 times.
2. What is the output of the following code
>>>‘a’ in “computer”
3. What is the output of the following code
Strg=”computer”
print(Strg[ 0: 8 : 2]
4. What is the output of the following? print('INDIA'.capitalize())
2 Mark Questions
Sr. Question
1. If you give the following for str1=”Hello” why does python report error
str1[2]=’p’
2. Identify the output of the following Python statements.
x="Vidyalaya"
y="Vidya"
if(y in x):
print(y)
5. Find the value stored in ctr at the end of this code snippet:
mystr="Darjeeling Tea has a strong flavour"
ctr=0
for i in mystr:
if i in 'aeiouAEIOU':
ctr += 1
print(ctr)
3 Mark Questions
Sr. Question
1. Write a Python program to input a line of text and a character from user to print the
frequency of the character in the line. For example
Line entered is : this is a golden pen The character to search : e
Then output is : Frequency is 2
2. Write a Python Program to input a string to check whether it is a Palindrome string
or not. (A Palindrome string is that which is same from both ends like – NITIN,
MALAYALAM, PULLUP)
3. Using string replication techniques print the following pattern using any loop.
Hello Hello Hello
Hello Hello Hello
4 Mark Questions
Sr. Question
1. Find Output:
my_string = 'Jhunjhunu'
print(my_string[:3])
for i in range(len(my_string)):
print(my_string[i].upper(),end="@")
print()
print (my_string)
print (my_string[3:6])
2. Consider the following string mySubject: mySubject = "Computer Science"
What will be the output of the following string operations :
print(mySubject[0:len(mySubject)])
print(mySubject[-7:-1])
print(mySubject[::2])
print(mySubject[len(mySubject)-1])
print(2*mySubject)
print(mySubject[::-2])
3. Consider the following string country: country= "Great India"
What will be the output of the following string operations(Any Four):-
a) print(country[0:len(country)])
b) print(country[-7:-1])
c) print(country[::2])
d) print(country[len(country)-1])
e) print(2*country)
f) print(country[:3] + country[3:])