Table of Contents
Multiple Choice Questions
Question 1
Negative index -1 belongs to ………. of string.
- first character
- last character ✓
- second last character
- second character
Question 2
Which of the following is/are not legal string operators?
- in
- +
- *
- / ✓
Question 3
Which of the following functions will return the total number of characters in a string?
- count()
- index()
- len() ✓
- all of these
Question 4
Which of the following functions will return the last three characters of a string s?
- s[3:]
- s[:3]
- s[-3:] ✓
- s[:-3]
Question 5
Which of the following functions will return the first three characters of a string s?
- s[3:]
- s[:3] ✓
- s[-3:]
- s[:-3]
Question 6
Which of the following functions will return the string in all caps?
- upper() ✓
- toupper()
- isupper()
- to-upper()
Question 7
Which of the following functions will return the string with every ‘P’ replaced with a ‘z’?
- find()
- index()
- replace() ✓
- split()
Question 8
Which of the following functions will return a list containing all words of the string?
- find()
- index()
- partition()
- split() ✓
Question 9
Which of the following functions will always return a tuple of 3 elements?
- find()
- index()
- partition() ✓
- split()
Question 10
What is the output of the following code?
str1 = "Mission 999" str2 = "999" print(str1.isdigit(),str2.isdigit())
- False True ✓
- False False
- True False
- True True
Question 11
Choose the correct function to get the ASCII code of a character.
- char(‘char’)
- ord(‘char’) ✓
- ascii(‘char’)
- All of these
Question 12
Which method should I use to convert String “Python programming is fun” to “Python Programming Is Fun” ?
- capitalize()
- title() ✓
- istitle()
- upper()
Question 13
Guess the correct output of the following String operations.
str1 = 'Wah' print(str1*2)
- WahWah ✓
- TypeError: unsupported operand type(s) for * : ‘str’ and ‘int’
- WWaahh
- Wah2
Question 14
What is the output of the following string operation?
str = "My roll no. is 12" print(str.isalnum())
- True
- False ✓
- Error
- No output
Question 15
Select the correct output of the following String operations.
str1 = 'Waha' print(str1[:3] + 'Bhyi' + str1[-3:])
- Wah Bhyi Wah
- WahBhyiaha ✓
- WahBhyiWah
- WahBhyiWaha
Question 16
Select the correct output of the following String operations.
str = "my name is Anu John" print(str.capitalize())
- ‘My name is anu john’ ✓
- TypeError: unsupported operand type(s) for * : ‘str’ and ‘int’
- ‘My name is Anu John’
- ‘My Name Is Anu John’
Question 17
Choose the correct function to get the character from ASCII number.
- ascii(number)
- char(number)
- chr(number) ✓
- all of these
Question 18
s = ‘ ‘(single space). Then s.isalnum() will return.
- True
- False ✓
- Error
- nothing
Question 19
Which of the following functions removes all leading and trailing spaces from a string?
- lstrip()
- rstrip()
- strip() ✓
- all of these
Question 20
Which of the following functions will raise an error if the given substring is not found in the string?
- find()
- index() ✓
- replace()
- all of these
Discover more from EduGrown School
Subscribe to get the latest posts sent to your email.