1. Python does not support a character type; a single character is treated as strings of length one.
A. False
B. True
Ans : True
2. Strings are immutable in Python, which means a string cannot be modified.
A. True
B. False
Ans : True
3. What will be the output of the following Python code?
>>>str1="helloworld"
>>>str1[::-1]
A. dlrowolleh
B. hello
C. world
D. helloworld
Ans : dlrowolleh
4. What will be the output of the following Python code?
>>>print (r"\nhello")
A. a new line and hello
B. \nhello
C. the letter r and then hello
D. error
Ans : \nhello
5. Which of the following will result in an error?
str1="python"
A. print(str1[2])
B. str1[1]="x"
C. print(str1[0:9])
D. Both (b) and (c)
Ans : str1[1]="x"
6. What will be the output of below Python code?
str1="Information"
print(str1[2:8])
A. format
B. formatio
C. orma
D. ormat
Ans : format
7. What arithmetic operators cannot be used with strings?
A. +
B. *
C. –
D. All of the mentioned
Ans : –
8. What will following Python code return?
str1="Stack of books"
print(len(str1))
A. 13
B. 14
C. 15
D. 16
Ans : 14
9. What will be the output of the following Python code?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]
A. olleh
B. hello
C. h
D. o
Ans : o
10. What will be the output of the following Python statement?
>>>"abcd"[2:]
A. a
B. ab
C. cd
D. dc
Ans : cd
11. What will be the output of below Python code?
str1="Aplication"
str2=str1.replace('a','A')
print(str2)
A. application
B. Application
C. ApplicAtion
D. applicAtion
Ans : ApplicAtion
12. Which of the following will give "Simon" as output?
If str1="John,Simon,Aryan"
A. print(str1[-7:-12])
B. print(str1[-11:-7])
C. print(str1[-11:-6])
D. print(str1[-7:-11])
Ans : print(str1[-11:-6])
13. Given a string example=”hello” what is the output of example.count(‘l’)?
A. 2
B. 1
C. None
D. 0
Ans : 2
14. What will be the output of the following Python code?
class tester:
def __init__(self, id):
self.id = str(id)
id="224"
>>>temp = tester(12)
>>>print(temp.id)
A. 224
B. Error
C. 12
D. None
Ans : 12
15. What will be the output of the following Python code?
>>>max("what are you")
A. error
B. u
C. t
D. y
Ans : y
16. What will be the output of the following Python statement?
>>>print(chr(ord('b')+1))
A. a
B. b
C. c
D. A
Ans : c
17. The format function, when applied on a string returns ___________
A. Error
B. int
C. bool
D. str
Ans : str
18. What will be the output of the following Python statement?
>>>chr(ord('A'))
A. A
B. B
C. a
D. Error
Ans : A
19. What will be displayed by print(ord(‘b’) – ord(‘a’))?
A. 0
B. 1
C. -1
D. 2
Ans : 1
20. If a class defines the __str__(self) method, for an object obj for the class, you can use which command to invoke the __str__ method.
A. obj.__str__()
B. str(obj)
C. print obj
D. all of the mentioned
Ans : all of the mentioned
0 Comments