0% found this document useful (0 votes)
10 views

string exam quwstion

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

string exam quwstion

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Exam on string Class XI(Csc.

)
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. TypeError: unsupported operand type(s) for * : 'str' and 'int'


3. WWaahh
4. Wah2
5. Select the correct output of the following String operations.
str1 = 'Waha'
print(str1[:3] + 'Bhyi' + str1[-3:])

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

1. What is the result of following statement, if the input is 'Fun'?


print(input("...") + "trial" + "Ooty" * 3)
2. From the string S = "CARPE DIEM", which ranges return "DIE" and "CAR"?
3. What would the following expressions return?
1. "Hello World".upper( ).lower( )
2. "Hello World".lower( ).upper( )
3. "Hello World".find("Wor", 1, 6)
4. "Hello World".find("Wor")
5. "Hello World".find("wor")
6. "Hello World".isalpha( )
7. "Hello World".isalnum( )
8. "1234".isdigit( )
9. "123FGH".isdigit( )
4. Suggest appropriate functions for the following tasks:
1. To check whether the string contains digits
2. To find for the occurrence a string within another string
3. To convert the first letter of a string to upper case
4. to capitalize all the letters of the string
5. to check whether all letters of the string are in capital letters
6. to remove from right of a string all string-combinations from a given set of letters
7. to remove all white spaces from the beginning of a string
5. What will be the output produced by following code fragments?
x = "hello world"
print (x[:2], x[:-2], x[-2:])
print (x[6], x[2:4])
print (x[2:-3], x[-4:-2])
6. Which functions would you choose to use to remove leading and trailing white spaces from a
given string?
7. What is similarity and difference between partition() and split() method?

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 “-”.

You might also like