Python Objective Question
Python Objective Question
a) int
b) long
c) float
d) complex
Answer: b
1. >>>str="hello"
2. >>>str[:2]
3. >>>
a) he
b) lo
c) olleh
d) hello
Answer: a
Answer: a
6. What error occurs when you execute the following Python code snippet?
apple = mango
a) SyntaxError
b) NameError
c) ValueError
d) TypeError
Answer: b
1. def example(a):
2. a = a +'2'
3. a = a*2
4. return a
5. example("hello")
a) Indentation Error
b) cannot perform mathematical operation on strings
c) hello2
d) hello2hello2
Answer: a
a) list
b) dictionary
c) array
d) tuple
Answer: a
9. In order to store values in terms of key and value we use what core data type.
a) list
b) tuple
c) class
d) dictionary
Answer: d
10. The following is displayed by a print function call. Select all of the function calls that
result in this output.
1. tom
2. dick
3. harry
a)
print('''tom
\ndick
\nharry''')
b) print(”’tomdickharry”’)
c) print(‘tom\ndick\nharry’)
d)print('tomdickharry')
Answer: c
hello-how-are-you
Answer: c
Answer: a
Answer: b
Answer: b
Answer: a
Answer: b
Answer: b
18. Operators with the same precedence are generally evaluated in which manner?
a) Left to Right (except exponent/power)
b) Right to Left
c) Left to Right
d) None of the mentioned
Answer: a
Answer: c
20. Which one of the following has the same precedence level?
a) Addition and Subtraction
b) Multiplication, Division and Addition
c) Multiplication, Division, Addition and Subtraction
d) Addition and Multiplication
Answer: a
a) Error
b) 12
c) 15
d) 1512
Answer: c
a) Error
b) 100
c) 101
d) 99
Answer: b
a) 13
b) 10
c) 2
d) 5
Answer: a
a) Error
b) 13
c)13x
d) x
Answer: d
a) error
b) hello
c) 16
d)16hello
Answer: a
a) Error
b) 12 4
c) 4 12
d) 4 15
Answer: c
a)
hello
hello
world
b)
world
world
hello
c)
hello
world
world
d)
world
hello
world
Answer: b
a) [3,2,4]
b) [2,3,4]
c) Error
d) [3,4,2]
Answer: d
a) 1 2 3 4
b) 5 10 15 4
c) 10 20 30 40
d) 5 10 15 40
Answer: c
a)
outer
error
b)
inner
error
c)
outer
inner
d) error
Answer: a
def f2(a,b):
global x
return a+b+x
f1()
total= f2(1,2)
print(total)
a) Error
b) 7
c) 8
d) 15
Answer: b
def f2():
global x
x=80
print(x)
a) 100
b) 90
c) 80
d) Error
Answer: a
33. Read the following Python code carefully and point out the global variables?
y, z =1,2
def f():
global x
x =y+z
a) x
b) y and z
c) x, y and z
d) Neither x, nor y, nor z
Answer: c
Answer: b
Answer: c
a) 1
b) Nothing is displayed
c) 0
d) An exception is thrown
Answer: c
c =[1,2,3,4]
a(c)
print(len(c))
a) 4
b) 5
c) 1
d) An exception is thrown
Answer: a
a)
10
56
b)
45
56
c)
10
20
d) Syntax Error
Answer: a
Answer: d
a) Integer
b) Tuple
c) Dictionary
d) An exception is thrown
Answer: b
41. If a function doesn’t have a return statement, which of the following does the function
return?
a) int
b) null
c) None
d) An exception is thrown without the return statement
Answer: c
a) zzz
b) zz
c) An exception is executed
d) Infinite loop
Answer: a
43. What will be the output of the following Python code?
def find(a, **b):
print(type(b))
find('letters',A='1',B='2')
a) String
b) Tuple
c) Dictionary
d) An exception is thrown
Answer: c
44. _____ represents an entity in the real world with its identity and behavior.
a) A method
b) An object
c) A class
d) An operator
Answer: b
Answer: b
def display(self):
print(self.a)
obj=test()
obj.display()
a) The program has an error because constructor can’t have default arguments
b) Nothing is displayed
c) “Hello World” is displayed
d) The program has an error display function doesn’t have parameters
Answer: c
def display(self):
print(self.a)
obj=test()
obj.display()
Answer: c
a) Correct
b) Incorrect
Answer: a
Answer: c
Answer: d