Multiple Choice Questions

Question 1

Negative index -1 belongs to ………. of string.

  1. first character
  2. last character ✓
  3. second last character
  4. second character

Question 2

Which of the following is/are not legal string operators?

  1. in
  2. +
  3. *
  4. / ✓

Question 3

Which of the following functions will return the total number of characters in a string?

  1. count()
  2. index()
  3. len() ✓
  4. all of these

Question 4

Which of the following functions will return the last three characters of a string s?

  1. s[3:]
  2. s[:3]
  3. s[-3:] ✓
  4. s[:-3]

Question 5

Which of the following functions will return the first three characters of a string s?

  1. s[3:]
  2. s[:3] ✓
  3. s[-3:]
  4. s[:-3]

Question 6

Which of the following functions will return the string in all caps?

  1. upper() ✓
  2. toupper()
  3. isupper()
  4. to-upper()

Question 7

Which of the following functions will return the string with every ‘P’ replaced with a ‘z’?

  1. find()
  2. index()
  3. replace() ✓
  4. split()

Question 8

Which of the following functions will return a list containing all words of the string?

  1. find()
  2. index()
  3. partition()
  4. split() ✓

Question 9

Which of the following functions will always return a tuple of 3 elements?

  1. find()
  2. index()
  3. partition() ✓
  4. split()

Question 10

What is the output of the following code?

str1 = "Mission 999"
str2 = "999"
print(str1.isdigit(),str2.isdigit())
  1. False True ✓
  2. False False
  3. True False
  4. True True

Question 11

Choose the correct function to get the ASCII code of a character.

  1. char(‘char’)
  2. ord(‘char’) ✓
  3. ascii(‘char’)
  4. All of these

Question 12

Which method should I use to convert String “Python programming is fun” to “Python Programming Is Fun” ?

  1. capitalize()
  2. title() ✓
  3. istitle()
  4. upper()

Question 13

Guess the correct output of the following String operations.

str1 = 'Wah'
print(str1*2)
  1. WahWah ✓
  2. TypeError: unsupported operand type(s) for * : ‘str’ and ‘int’
  3. WWaahh
  4. Wah2

Question 14

What is the output of the following string operation?

str = "My roll no. is 12"
print(str.isalnum())
  1. True
  2. False ✓
  3. Error
  4. No output

Question 15

Select the correct output of the following String operations.

str1 = 'Waha'
print(str1[:3] + 'Bhyi' + str1[-3:])
  1. Wah Bhyi Wah
  2. WahBhyiaha ✓
  3. WahBhyiWah
  4. WahBhyiWaha

Question 16

Select the correct output of the following String operations.

str = "my name is Anu John"
print(str.capitalize())
  1. ‘My name is anu john’ ✓
  2. TypeError: unsupported operand type(s) for * : ‘str’ and ‘int’
  3. ‘My name is Anu John’
  4. ‘My Name Is Anu John’

Question 17

Choose the correct function to get the character from ASCII number.

  1. ascii(number)
  2. char(number)
  3. chr(number) ✓
  4. all of these

Question 18

s = ‘ ‘(single space). Then s.isalnum() will return.

  1. True
  2. False ✓
  3. Error
  4. nothing

Question 19

Which of the following functions removes all leading and trailing spaces from a string?

  1. lstrip()
  2. rstrip()
  3. strip() ✓
  4. all of these

Question 20

Which of the following functions will raise an error if the given substring is not found in the string?

  1. find()
  2. index() ✓
  3. replace()
  4. all of these


Discover more from EduGrown School

Subscribe to get the latest posts sent to your email.