MCQOPTIONS
Saved Bookmarks
This section includes 1007 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.
| 801. |
What is the output of the following? print("abcdef".center()) |
| A. | cd |
| B. | abcdef |
| C. | error |
| D. | none of the mentioned |
| Answer» D. none of the mentioned | |
| 802. |
What is the output of the following? print("abc. DEF".capitalize()) |
| A. | abc. def |
| B. | ABC. DEF |
| C. | Abc. def |
| D. | Abc. Def |
| Answer» D. Abc. Def | |
| 803. |
What is the output of the following? print("abc DEF".capitalize()) |
| A. | abc def |
| B. | ABC DEF |
| C. | Abc def |
| D. | Abc Def |
| Answer» D. Abc Def | |
| 804. |
Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space) |
| A. | __345.355 |
| B. | ___345.355 |
| C. | ____345.355 |
| D. | _____345.354 |
| Answer» C. ____345.355 | |
| 805. |
What function do you use to read a string? |
| A. | input(“Enter a string”) |
| B. | eval(input(“Enter a string”)) |
| C. | enter(“Enter a string”) |
| D. | eval(enter(“Enter a string”)) |
| Answer» B. eval(input(“Enter a string”)) | |
| 806. |
Suppose i is 5 and j is 4, i + j is same as |
| A. | i.__add(j) |
| B. | i.__add__(j) |
| C. | i.__Add(j) |
| D. | i.__ADD(j) |
| Answer» C. i.__Add(j) | |
| 807. |
To check whether string s1 contains another string s2, use |
| A. | s1.__contains__(s2) |
| B. | s2 in s1 |
| C. | s1.contains(s2) |
| D. | si.in(s2) |
| Answer» B. s2 in s1 | |
| 808. |
f 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. | |
| 809. |
To return the length of string s what command do we execute ? |
| A. | s.__len__() |
| B. | en(s) |
| C. | en(s) |
| D. | s.size() |
| Answer» B. en(s) | |
| 810. |
To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed) ? |
| A. | s[]. |
| B. | s.getitem(3) |
| C. | s.__getitem__(3) |
| D. | s.getItem(3) |
| Answer» D. s.getItem(3) | |
| 811. |
What is “Hello”.replace(“l”, “e”) |
| A. | Heeeo |
| B. | Heelo |
| C. | Heelo |
| D. | None |
| Answer» B. Heelo | |
| 812. |
Say s=”hello” what will be the return value of type(s) ? |
| A. | int |
| B. | bool |
| C. | str |
| D. | String |
| Answer» D. String | |
| 813. |
What will be displayed by print(ord(‘b’) – ord(‘a’)) ? |
| A. | 0 |
| B. | 1 |
| C. | -1 |
| D. | 2 |
| Answer» C. -1 | |
| 814. |
What is the output when following statement is executed ?(python 3.xx) >>>print(format("Welcome", "10s"), end = '#') >>>print(format(111, "4d"), end = '#') >>>print(format(924.656, "3.2f")) |
| A. | Welcome# 111#924.66 |
| B. | Welcome#111#924.66 |
| C. | Welcome#111#.66 |
| D. | Welcome # 111#924.66 |
| Answer» E. | |
| 815. |
What is the output when following code is executed ? >>>print("D", end = ' ') >>>print("C", end = ' ') >>>print("B", end = ' ') >>>print("A", end = ' ') |
| A. | DCBA |
| B. | A, B, C, D |
| C. | D C B A |
| D. | D, C, B, A will be displayed on four lines |
| Answer» E. | |
| 816. |
What is the output of “hello”+1+2+3 ? |
| A. | hello123 |
| B. | hello |
| C. | Error |
| D. | hello6 |
| Answer» D. hello6 | |
| 817. |
The format function, when applied on a string returns : |
| A. | Error |
| B. | int |
| C. | bool |
| D. | str |
| Answer» E. | |
| 818. |
Suppose s is “\t\tWorld\n”, what is s.strip() ? |
| A. | World |
| B. | World |
| C. | WORLD |
| D. | World |
| Answer» E. | |
| 819. |
Which of the following statement prints hello\example\test.txt ? |
| A. | print(“helloexampleest.txt”) |
| B. | print(“helloexampleest.txt”) |
| C. | print(“hello”example”test.txt”) |
| D. | print(“hello”example”est.txt”) |
| Answer» C. print(“hello”example”test.txt”) | |
| 820. |
What is the output when following statement is executed ? >>>print(chr(ord('b')+1)) |
| A. | a |
| B. | b |
| C. | c |
| D. | A |
| Answer» D. A | |
| 821. |
What is the output when following statement is executed ? >>>chr(ord('A')) |
| A. | A |
| B. | B |
| C. | a |
| D. | Error |
| Answer» B. B | |
| 822. |
To concatenate two strings to a third what statements are applicable ? |
| A. | s3 = s1 . s2 |
| B. | s3 = s1.add(s2) |
| C. | s3 = s1.__add__(s2) |
| D. | s3 = s1 * s2 |
| Answer» D. s3 = s1 * s2 | |
| 823. |
What is the output of the following code ? >>>example="helloworld" >>>example[::-1].startswith("d") |
| A. | dlrowolleh |
| B. | True |
| C. | -1 |
| D. | None |
| Answer» C. -1 | |
| 824. |
What is the output of the following code ? >>>example = "helle" >>>example.rfind("e") |
| A. | -1 |
| B. | 4 |
| C. | 3 |
| D. | 1 |
| Answer» C. 3 | |
| 825. |
Given a string example=”hello” what is the output of example.count(l) |
| A. | 2 |
| B. | 1 |
| C. | None |
| D. | 0 |
| Answer» B. 1 | |
| 826. |
What is the output of the following code ? >>>max("what are you") |
| A. | error |
| B. | u |
| C. | t |
| D. | y |
| Answer» E. | |
| 827. |
What is the output of the following code ? >>>example = "snow world" >>>example[3] = 's' >>>print example |
| A. | snow |
| B. | snow world |
| C. | Error |
| D. | snos world |
| Answer» D. snos world | |
| 828. |
What is the output of the following code ? >>>example = "snow world" >>>print("%s" % example[4:7]) |
| A. | wo |
| B. | world |
| C. | sn |
| D. | rl |
| Answer» B. world | |
| 829. |
What is the output of the following 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 |
| Answer» D. None | |
| 830. |
print(0xA + 0xB + 0xC) : |
| A. | 0xA0xB0xC |
| B. | Error |
| C. | 0x22 |
| D. | 33 |
| Answer» E. | |
| 831. |
What is the output when following code is executed ? >>>str1="helloworld" >>>str1[::-1] |
| A. | dlrowolleh |
| B. | hello |
| C. | world |
| D. | helloworld |
| Answer» B. hello | |
| 832. |
What is the output when following statement is executed ? >>> print(‘x\97\x98’) |
| A. | Error |
| B. | 97 98 |
| C. | x97 |
| D. | x97x98 |
| Answer» D. x97x98 | |
| 833. |
What is the output when following statement is executed ? >>>print('new' 'line') |
| A. | Error |
| B. | Output equivalent to print ‘newline’ |
| C. | newline |
| D. | new line |
| Answer» D. new line | |
| 834. |
What is the output when following code is executed ? >>>print r"\nhello" The output is |
| A. | a new line and hello |
| B. | hello |
| C. | the letter r and then hello |
| D. | error |
| Answer» C. the letter r and then hello | |
| 835. |
What arithmetic operators cannot be used with strings ? |
| A. | + |
| B. | * |
| C. | – |
| D. | All of the mentioned |
| Answer» D. All of the mentioned | |
| 836. |
What is the output when following code is executed ? >>> str1 = 'hello' >>> str2 = ',' >>> str3 = 'world' >>> str1[-1:] |
| A. | olleh |
| B. | hello |
| C. | h |
| D. | o |
| Answer» E. | |
| 837. |
The output of executing string.ascii_letters can also be achieved by: |
| A. | string.ascii_lowercase_string.digits |
| B. | string.ascii_lowercase+string.ascii_upercase |
| C. | string.letters |
| D. | string.lowercase_string.upercase |
| Answer» C. string.letters | |
| 838. |
What is the output when following statement is executed ? >>>"abcd"[2:] |
| A. | a |
| B. | ab |
| C. | cd |
| D. | dc |
| Answer» D. dc | |
| 839. |
What is the output when following statement is executed ? >>>"a"+"bc" |
| A. | a |
| B. | bc |
| C. | bca |
| D. | abc |
| Answer» E. | |
| 840. |
What is the output of the following? x = 2 for i in range(x): x -= 2 print (x) |
| A. | 0 1 2 3 4 … |
| B. | 0 -2 |
| C. | 0 |
| D. | error |
| Answer» C. 0 | |
| 841. |
What is the output of the following? x = 2 for i in range(x): x += 1 print (x) |
| A. | 0 1 2 3 4 … |
| B. | 0 1 |
| C. | 3 4 |
| D. | 0 1 2 3 |
| Answer» D. 0 1 2 3 | |
| 842. |
What is the output of the following? for i in '': print (i) |
| A. | None |
| B. | (nothing is printed) |
| C. | error |
| D. | none of the mentioned |
| Answer» C. error | |
| 843. |
What is the output of the following? for i in 'abcd'[::-1]: print (i) |
| A. | a b c d |
| B. | d c b a |
| C. | error |
| D. | none of the mentioned |
| Answer» C. error | |
| 844. |
What is the output of the following? for i in ''.join(reversed(list('abcd'))): print (i) |
| A. | a b c d |
| B. | d c b a |
| C. | error |
| D. | none of the mentioned |
| Answer» C. error | |
| 845. |
What is the output of the following? for i in [1, 2, 3, 4][::-1]: print (i) |
| A. | 1 2 3 4 |
| B. | 4 3 2 1 |
| C. | 4 3 2 1 |
| D. | none of the mentioned |
| Answer» C. 4 3 2 1 | |
| 846. |
What is the output of the following? for i in range(int(float('inf'))): print (i) |
| A. | 0.0 0.1 0.2 0.3 … |
| B. | 0 1 2 3 … |
| C. | 0.0 1.0 2.0 3.0 … |
| D. | none of the mentioned |
| Answer» E. | |
| 847. |
What is the output of the following? for i in range(float('inf')): print (i) |
| A. | 0.0 0.1 0.2 0.3 … |
| B. | 0 1 2 3 … |
| C. | 0.0 1.0 2.0 3.0 … |
| D. | none of the mentioned |
| Answer» E. | |
| 848. |
What is the output of the following? for i in range(int(2.0)): print(i) |
| A. | 0.0 1.0 |
| B. | 0 1 |
| C. | error |
| D. | none of the mentioned |
| Answer» C. error | |
| 849. |
What is the output of the following? for i in range(2.0): print(i) |
| A. | 0.0 1.0 |
| B. | 0 1 |
| C. | error |
| D. | none of the mentioned |
| Answer» D. none of the mentioned | |
| 850. |
What is the output of the following? for i in range(0): print(i) |
| A. | 0 |
| B. | no output |
| C. | error |
| D. | none of the mentioned |
| Answer» C. error | |