

MCQOPTIONS
Saved Bookmarks
This section includes 9 Mcqs, each offering curated multiple-choice questions to sharpen your Python knowledge and support exam preparation. Choose a topic below to get started.
1. |
What is the output of the following code ? |
A. | -1 |
B. | 4 |
C. | 3 |
D. | 1 |
Answer» C. 3 | |
2. |
What is the output when following statement is executed ?(python 3.xx) |
A. | Welcome# 111#924.66 |
B. | Welcome#111#924.66 |
C. | Welcome#111#.66 |
D. | Welcome # 111#924.66 |
Answer» E. | |
3. |
To retrieve the character at index 3 from string s=”Hello” , what command do we execute ? |
A. | s[]. |
B. | s.getitem(3) |
C. | s.__getitem__(3) |
D. | s.getItem(3) |
Answer» D. s.getItem(3) | |
4. |
What is the output of “hello”+1+2+3 ? |
A. | hello123 |
B. | hello |
C. | Error |
D. | hello6 |
Answer» D. hello6 | |
5. |
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 |
Answer» E. | |
6. |
Which of the following statement prints hello\example\test.txt ? |
A. | print(“hello\example\test.txt”) |
B. | print(“hello\\example\\test.txt”) |
C. | print(“hello\”example\”test.txt”) |
D. | print(“hello”\example”\test.txt”) |
Answer» C. print(“hello\”example\”test.txt”) | |
7. |
To return the length of string s what command do we execute ? |
A. | s.__len__() |
B. | len(s) |
C. | size(s) |
D. | s.size() |
Answer» B. len(s) | |
8. |
What is the output when following statement is executed ? |
A. | Error |
B. | 9798 |
C. | x\97 |
D. | \x97\x98 |
Answer» D. \x97\x98 | |
9. |
What is the output when following code is executed ? |
A. | dlrowolleh |
B. | hello |
C. | world |
D. | helloworld |
Answer» B. hello | |