String Assignment in Python Set 1- Important Practice Exercise

Share with others

String Assignment in Python



Time: 30 min                                                                                   M.M. – 20


  • All Questions are compulsory
  • Q1 to Q6 carry 1 mark
  • Q7 to Q10 carry 2 marks
  • Q11 to Q12 carry 3 marks

Q1. Write the code to create an empty string named “str”.

Q2. Name the function which count the total number of characters in a string.

Q3. Fill the index value in place of ‘?’ so that the output should come ‘o’

       str = “”


Q4. Write the function which removes the spaces from the left side of the string.

Q5. What type of error is returned by the following statement?

        str = “”

        str[7] = ‘e’

Q6. What do you mean by concatenation of string?

Q7. Write a program to accept a string and display in reverse.

Q8. Write a function count( ) in python which takes string as argument and return total number of words.

Q9. Write the output of the following:

  1. print(“Suman” > “Sumati”)
  2. print(“amit”.isalpha())

Q10. Write the output of the following code :

str = “CSIPLearningHuB”

newstr = ” “

for i in range(len(str)):

    if str[i].isupper():

        newstr =newstr + str[i].lower()

    if str[i].islower():

        newstr =newstr + str[i].upper()


Q11. Write a program in python that accept a string from the user and display the following:

  1. Total number of vowels
  2. Total number of digits
  3. Total number of words.

Q12. Write the output of the following:

str = “CSIPLearningHuB”

print(str[: :-1])

print(str[-7: -1: 2])

print(str[3 : 14 : 3])

Disclaimer : I tried to give you the correct questions of “String Assignment in Python ” , but if you feel that there is/are mistakes in the questions of “String Assignment in Python “ given above, you can directly contact me at Also Share your feedback so that I can give better content to you.

Class 12 Computer Science Sample Paper 2020-2021.

Class 12 Computer Science Sample Paper Marking Scheme

Class 12 Computer Science Test Series

Share with others

Leave a Reply

%d bloggers like this: