string exam quwstion
string exam quwstion
)
SECTION -A
1. Which of the following functions will return the last three characters of a string s?
1. s[3:]
3. s[-3:] ✓
2. s[:3]
4. s[:-3]
2. Which of the following functions will return the first three characters of a string s?
2. s[:3] ✓
1. s[3:]
3. s[-3:]
4. s[:-3]
3. What is the output of the following code?
str1 = "Mission 999"
str2 = "999"
1. False True ✓
print(str1.isdigit(),str2.isdigit())
2. False False
3. True False
4. True True
4. Guess the correct output of the following String operations.
str1 = 'Wah'
1. WahWah ✓
print(str1*2)
2. WahBhyiaha ✓
1. Wah Bhyi Wah
3. WahBhyiWah
4. WahBhyiWaha
6. Which of the following functions removes all leading and trailing spaces from a string?
1. lstrip()
3. strip() ✓
2. rstrip()
4. all of these
SECTION- B
SECTION –C ANY 7
1. Write a Python script that traverses through an input string and prints its characters in
different lines — two characters per line.
2. Write a program to count the number times a character occurs in a given string.
3. Write a program which accepts a string and replaces all vowels in the string with “*”.
4. Write a program to input a string and print it in reverse order without creating a new
string.
5. Write a program to input a string and print it in reverse order using a for loop.
6. Write a program to input a string and check if the string is palindrome or not( A string is
called palindrome if it reads the same backwards as forward, mom is a palindrome).
7. Write a program to input lines of the text from the user until enter is pressed. Count the
total number of characters in the text(including white spaces), total no of digits, total
number of special symbols and total no of words in the given text,( Assume each word is
separated by one space).
8. Write a program to input lines of text and apply the title function if entered text has more
than one word.
9. Write a program to input a string and character and delete the occurrence of the character
in the given string.
10. Write a program to input a string having some digits. Print the sum of digits present in its
string.
11. Write a program to input a text of lines,( Assume each word is separated by one space).
Replace space with “-”.