Python MCQ With Answer TEST-1
Python MCQ With Answer TEST-1
a) Lists
b) Dictionary
c) Tuples
d) Class
d) Class
2. Given a function that does not return any value, What value is thrown by default when executed in shell.
a) int
b) bool
c) void
d) None
d) None
3.Following set of commands are executed in shell, what will be the output? if >>>str="hello" then >>>str[:2] is
a) he
b) lo
c) olleh
d) hello
a) he
4.In python we do not specify types,it is directly interpreted by the compiler, so consider the following operation to
be performed.>>>x = 13 ? 2 objective is to make sure x has a integer value, select all that apply (python 3.xx)
a) x = 13 // 2
b) x = int(13 / 2)
c) x = 13 % 2
a) SyntaxError
b) NameError
c) ValueError
d) TypeError
b) NameError
6.What is the average value of the code that is executed below ?if >>>grade1 = 80 and >>>grade2 = 90 then
>>>average = (float(grade1) + grade2) / 4
a) 42.0
b) 42.5
c) 42
d) 42.50
b) 42.5
7.What is the output of print(0.1 + 0.2 == 0.3) and print ((0.1 + 0.2) is 0.3) is ?
a) True, False
b) False, False
c) Machine dependent
d) Error
b) False, False
a) k = 2 + 3j
b) k = complex(2, 3)
c) k = 2 + 3l
d) k = 2 + 3J
c) k = 2 + 3l
9.What does ~~~~~~5 evaluate to?
a) +5
b) -11
c) +11
d) -5
a) +5
10.What is the output when following code is executed ?>>> str1 = 'hello' after that >>> str2 = ',' after that >>> str3 =
'world' and then >>> str1[-1:]
a) olleh
b) hello
c) h
d) o
a) olleh
a) Error
b) 97 98
c) x\97
d) \x97\x98
c) x\97
12.What is the output when following code is executed ? if >>>str1="helloworld" then >>>str1[::-1]
a) dlrowolleh
b) hello
c) world
d) helloworld
a) dlrowolleh
13.Process of removing errors called
a) Error Free
b) Debug
c) Syntax Error
d) Exception
b) Debug
a) list1 = list()
b) list1 = [].
b) *‘hello’+.
c) *‘llo’+.
d) *‘olleh’+.
a) 5
b) 4
c) None
d) Error
a) 5
b) [1, 3, 2, 1, 3].
c) [1, 3, 2, 1, 3, 2] .
D) [1, 3, 2, 3, 2, 1].
c) [1, 3, 2, 1, 3, 2] .
a) 40
b) 45
c) “john”
d) “peter”
a) 40
a) Tuple
b) Integer
c) List
b) Integer
b) [2,3].
c) (2,3,4)
d) (2,3)
d) (2,3)
21.Is the following piece of code valid? >>> a=(1,2,3,4) then >>> del a
a) no
b) yes
c) Machine dependent
b) yes
a) 7
b) 2
c) 4
d) 1
a) 7
a) Indentation
b) Key
c) Brackets
a) Indentation
26.What will be the output of the following Python code snipped if x=1 then X<<2
a) 4
b) 2
c) 1
d) 8
a) 4
a) underscore and ampersand are the only two special characters allowed
b) unlimited length
b) unlimited length
28.What are the values of the following Python expressions? 2**(3**2), (2**3)**2, 2**3**2
c) 64, 512, 64
d) 64, 64, 64
a) |
b) //
c) /
d) %
b) //
a) ( )
b) [ ]
c) { }
d) set()
d) set()
a) 79 characters
b) 31 characters
c) 63 characters
a) unlimited length
c) underscore and ampersand are the only two special characters allowed
a) unlimited length
a) abc = 1,000,000
d) a_b_c = 1,000,000
b) a b c = 1000 2000 3000
34.What is the order of precedence in python?i) Parentheses, ii) Exponential, iii) Multiplication, iv. Division, v)
Addition, vi) Subtraction
a) i,ii,iii,iv,v,vi
b) ii,i,iii,iv,v,vi
c) ii,i,iv,iii,v,vi
d) i,ii,iii,iv,vi,v
a) i,ii,iii,iv,v,vi
a) 27
b) 9
c) 3
d) 1
c) 3
37.Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
d) Parentheses
38.Which of the following operators has its associativity from right to left?
a) +
b) //
c) %
d) **
d) **
a) 43
b) 44
c) 22
d) 23
b) 44
a) (6.0, 16.0)
b) (6.00, 16.00)
c) (6, 16)
d) (6.00, 16.0)
a) (6.0, 16.0)
a) (1.0, 4.0)
b) (1.0, 1.0)
c) (4.0. 1.0)
d) (4.0, 4.0)
a) (1.0, 4.0)
42.Which among the following list of operators has the highest precedence? +, -, **, %, /, <<, >>, |
a) <<, >>
b) **
c) |
d) %
b) **
a) 4.0 + float(3)
b) 5.3 + 6.3
c) 5.0 + 3
d) 3 + 7
a) 4.0 + float(3)
a) ‘0b10111’
b) ‘0b11101’
c) ‘0b11111’
d) ‘0b11011’
b) ‘0b11101’
a) 1011
b) 11
c) 13
d) 1101
a) 1011
46.To find the decimal value of 1111, that is 15, we can use the function:
a) int(1111,10)
b) int(‘1111’,10)
c) int(1111,2)
d) int(‘1111’,2)
d) int(‘1111’,2)
a) ‘0bx1000’
b) 8
c) 1000
d) ‘0b1000’
d) ‘0b1000’
a) 001101010
b) 110010101
c) 001101011
d) 110010100
a) 001101010
49.Bitwise _________ gives 1 if either of the bits is 1 and 0 when both of the bits are 1.
a) OR
b) AND
c) XOR
d) NOT
c) XOR
a) 1011011
b) 11010100
c) 11101011
d) 10110011
b) 11010100
51.What will be the output of the following Python code snippet? ['hello', 'morning'][bool('')]
a) error
b) no output
c) hello
d) morning
c) hello
a) print(“hello\example\test.txt”)
b) print(“hello\\example\\test.txt”)
c) print(“hello\”example\”test.txt”)
d) print(“hello”\example”\test.txt”)
b) print(“hello\\example\\test.txt”)
a) hello123
b) hello
c) Error
d) hello6
c) Error
b) *‘hello’+
c) *‘llo’+
d) *‘olleh’+
56.What is the syntax of the following Python code? >>> a=frozenset(set([5,6,7])) then >>> a
a) {5,6,7}
b) frozenset({5,6,7})
d) Syntax error
b) frozenset({5,6,7})
57.Is the following Python code valid? >>> a=frozenset([5,6,7]) than >>> a and >>> a.add(5) is
58.What will be the output of the following Python code? if >>> a={1,2,3} and >>> b=frozenset([3,4,5]) then >>> a-b
is
a) {1,2}
a) {1,2}
a) float
b) int
c) Number
d) Complex
c) Number
a) 15.0
b) 15
c) Value Error
d) None Of above
c) Value Error
a) 20,18,16,14,12
b) 12,14,16,18,20
c) Error
d) None of above
a) 20,18,16,14,12
c) Both Mutable
d) Both Immutable
a) True
b) 60
c) Python
d) False
c) Python
65.print(6 * 3 / 4 ** 2 // 5 – 8 )
(a) -10
(b) 8.0
(c) 10.0
(d) -8.0
(d) -8.0
a) Error
b) 1.0
c) 1.00
d) 1
b) 1.0
67.What will be the output of the following Python expression? 24//6%3, 24//4//2
a) (1,3)
b) (0,3)
c) (1,0)
d) (3,1)
a) (1,3)
68. Which of the following Boolean expressions is not logically equivalent to the other three?
a) not(-6<0 or-6>10)
c) not(-6<10 or-6==10)
d) not(-6>10 or-6==10)
d) not(-6>10 or-6==10)
69.Which of the following is not the correct syntax for creating a set?
a) set([[1,2],[3,4]])
b) set([1,2,2,3,4])
c) set((1,2,3,4))
d) {1,2,3,4}
a) set([[1,2],[3,4]])
a) Error
b) 2,3,10,-10
c) 2,-3,10,-10
d) 2,-3,10,10
b) 2,10,-3,-10
c) 2,-3,10,-10