String Assignment in Python
CHAPTER: STRING IN PYTHON
STRING ASSIGNMENT IN PYTHON SET – 1
Time: 30 min M.M. – 20
Instructions:
- 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 = “csiplearninghub.com”
print(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 = “csiplearninghub.com”
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:
- print(“Suman” > “Sumati”)
- 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()
print(newstr)
Q11. Write a program in python that accept a string from the user and display the following:
- Total number of vowels
- Total number of digits
- 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 csiplearninghub@gmail.com. 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