22. This is the first index in a string. a. -1 b. 1 c. 0 d. The size of the stri
ID: 3694517 • Letter: 2
Question
22. This is the first index in a string.
a. -1
b. 1
c. 0
d. The size of the string minus one
23. This is the last index in a string.
a. 1
b. 99
c. 0
d. The size of the string minus one
24. This will happen if you try to use an index that is out of range for a string.
a. A ValueError exception will occur.
b. An IndexError exception will occur.
c. The string will be erased and the program will continue to run.
d. Nothing - the invalid index will be ignored.
25. This function returns the length of a string.
a. length
b. size
c. len
d. lengthof
Explanation / Answer
Answers:
22. (c) 0
Reason : In computer systems, the string indices start always from 0 and end with n-1, n being the size of the string.
23.(d) The size of string minus one
Reason : Same as above.
24. (b) An IndexError exception will occur.
Reason : When a string index that is out of the range of string is specified an IndexError exception occurs and prints the following message :
IndexError: string index out of range
25. (c) len
len() function prints the size of a string. It takes string as input and return an integer value for the length of the input string as follows :
The above code output is :
Length of the string : 6
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.