Programming and Problem Solving
Programming and Problem Solving
Click to Here
तम्हला नोकरीच्या संदर्भ मध्ये काही update माहहती आमच्या या चॅनेल वर र्ेटलं
join Click To Here
तम्हाला जर नोकरी साठी तुम्हाला लागणारे daily current affair | notes | ebooks
Join Click to Here
Python MCQ
a. 16
b. 32
c. 64
d. None of these above
Explanation: The maximum possible length of an identifier is not defined in the python language. It can be of any
number.
a. Zim Den
b. Guido van Rossum
c. Niene Stom
d. Wick van Rossum
Explanation: Python language was developed by Guido van Rossum in the Netherlands.
a. 1995
b. 1972
c. 1981
d. 1989
a. English
b. PHP
c. C
d. All of the above
Answer: (b) C
5) Which one of the following is the correct extension of the Python file?
a. .py
b. .python
c. .p
d. None of these
a. 2008
b. 2000
c. 2010
d. 2005
a. Key
b. Brackets
c. Indentation
d. None of these
a. /
b. //
c. #
d. !
Answer: (c) #
9) Which of the following statements is correct regarding the object-oriented programming concept in Python?
Answer: (b) Objects are real-world entities while classes are not real
Explanation: None
class Name:
def __init__(javatpoint):
javajavatpoint = java
name1=Name("ABC")
name2=name1
a. It will throw the error as multiple references to the same object is not possible
b. id(name1) and id(name2) will have same value
c. Both name1 and name2 will have reference to two different objects of class Name
d. All of the above
Answer: (b) id(name1) and id(name2) will have same value
Explanation: "name1" and "name2" refer to the same object, so id(name1) and id(name2) will have the same value.
a. Object
b. Function
c. Attribute
d. Argument
a. _x = 2
b. __x = 3
c. __xyz__ = 5
d. None of these
Explanation: All declarations will execute successfully but at the expense of low readability.
13) Why does the name of local variables start with an underscore discouraged?
Explanation: Since there is no concept of private variables in Python language, the major underscore is used to
denote variables that cannot be accessed from outside the class.
14) Which of the following is not a keyword in Python language?
a. val
b. raise
c. try
d. with
15) Which of the following statements is correct for variable names in Python language?
Explanation: None
a. xyzp = 5,000,000
b. x y z p = 5000 6000 7000 8000
c. x,y,z,p = 5000, 6000, 7000, 8000
d. x_y_z_p = 5,000,000
a. _val
b. val
c. try
d. _try_
18) Which of the following operators is the correct option for power(ab)?
a. a ^ b
b. a**b
c. a ^ ^ b
d. a ^ * b
20) Which one of the following has the same precedence level?
Explanation: None
21) Which one of the following has the highest precedence in the expression?
a. Division
b. Subtraction
c. Power
d. Parentheses
Answer: (d) Parentheses
a. val()
b. print()
c. print()
d. None of these
Explanation: The print() function is a built-in function in python language that prints a value directly to the system.
round(4.576)
a. 4
b. 5
c. 576
d. 5
Answer: (d) 5
Explanation: The round function is a built-in function in the Python language that round-off the value (like 3.85 is
4), so the output of this function will be 5.
pow(x,y,z)
a. (x**y) / z
b. (x / y) * z
c. (x**y) % z
d. (x / y) / z
Answer: (c) (x**y) % z
all([2,4,0,6])
a. False
b. True
c. 0
d. Invalid code
Explanation: If any element is zero, it returns a false value, and if all elements are non-zero, it returns a true value.
Hence, the output of this "all([2,4,0,6])" function will be false.
x=1
while True:
if x % 5 = = 0:
break
print(x)
x+=1
a. error
b. 2 1
c. 0 3 1
d. None of these
Answer: (a) error
27) Which one of the following syntaxes is the correct syntax to read from a simple text file stored in ''d:\java.txt''?
Explanation: None
x = ['XX', 'YY']
for i in a:
i.lower()
print(a)
a. ['XX', 'YY']
b. ['xx', 'yy']
c. [XX, yy]
d. None of these
Explanation: None
29) Study the following function:
import math
abs(math.sqrt(36))
a. Error
b. -6
c. 6
d. 6.0
a. False
b. Ture
c. Invalid code
d. None of these
Explanation: None
>>>"a"+"bc"
Explanation: In Python, the "+" operator acts as a concatenation operator between two strings.
>>>"javatpoint"[5:]
a. javatpoint
b. java
c. point
d. None of these
a. character
b. ascii_lowercase_string.digits
c. lowercase_string.upercase
d. ascii_lowercase+string.ascii_upercase
Explanation: None
34) Study the following statements:
a. t
b. j
c. point
d. java
Answer: (a) t
Explanation: The correct output of this program is "t" because -1 corresponds to the last index.
a. java
point
b. java point
c. \njavat\npoint
d. Print the letter r and then javat and then point
Explanation: None
36) Study the following statements:
a. 33
b. 63
c. 0xA + 0xB + 0xC
d. None of these
Answer: (a) 33
Explanation: A, B and C are hexadecimal integers with values 10, 11 and 12 respectively, so the sum of A, B and C
is 33.
class book:
def __init__(a, b):
a.o1 = b
class child(book):
def __init__(a, b):
a.o2 = b
obj = page(32)
print "%d %d" % (obj.o1, obj.o2)
a. 32
b. 32 32
c. 32 None
d. Error is generated
Answer: (d) Error is generated
class Std_Name:
def __init__(self, Std_firstName, Std_Phn, Std_lastName):
self.Std_firstName = Std_firstName
self. Std_PhnStd_Phn = Std_Phn
self. Std_lastNameStd_lastName = Std_lastName
Std_firstName = "Wick"
name = Std_Name(Std_firstName, 'F', "Bob")
Std_firstName = "Ann"
name.lastName = "Nick"
print(name.Std_firstName, name.Std_lastName)
a. Ann Bob
b. Ann Nick
c. Wick Bob
d. Wick Nick
Explanation: None
a. 18
b. -18
c. 17
d. -17
Explanation: ASCII value of h is less than the z. Hence the output of this code is 104-122, which is equal to -18.
x = ['xy', 'yz']
for i in a:
i.upper()
print(a)
a. ['xy', 'yz']
b. ['XY', 'YZ']
c. [None, None]
d. None of these
Explanation: None
i = 1:
while True:
if i%3 == 0:
break
print(i)
a. 1 2 3
b. 3 2 1
c. 1 2
d. Invalid syntax
a=1
while True:
if a % 7 = = 0:
break
print(a)
a += 1
a. 1 2 3 4 5
b. 1 2 3 4 5 6
c. 1 2 3 4 5 6 7
d. Invalid syntax
Answer: (b) 1 2 3 4 5 6
Explanation: None
i=0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
a. 1 2 3
b. 0 1 2 3
c. 0 1 2
d. 3 2 1
Answer: (c) 0 1 2
Explanation: None
i=0
while i < 3:
print(i)
i += 1
else:
print(0)
a. 0 1
b. 0 1 2
c. 0 1 2 0
d. 0 1 2 3
Answer: (c) 0 1 2 0
Explanation: None
a. xyz
b. No output
c. x y z
d. j j j j j j j..
x = 'pqrs'
for i in range(len(x)):
x[i].upper()
print (x)
a. PQRS
b. pqrs
c. qrs
d. None of these
a. a b c
b. 0 1 2
c. 0 a 1b 2c
d. None of these above
Answer: (b) 0 1 2
Explanation: None
d = {0, 1, 2}
for x in d:
print(x)
Answer: (b) 0 1 2
Explanation: None
49) Which of the following option is not a core data type in the python language?
a. Dictionary
b. Lists
c. Class
d. All of the above
Explanation: Class is not a core data type because it is a user-defined data type.
50) What error will occur when you execute the following code?
MANGO = APPLE
a. NameError
b. SyntaxError
c. TypeError
d. ValueError
def example(a):
aa = a + '1'
aa = a*1
return a
>>>example("javatpoint")
a. hello2hello2
b. hello2
c. Cannot perform mathematical operation on strings
d. indentationError
Explanation: None
a. Dictionary
b. Tuple
c. List
d. Stack
a. False
b. Ture
c. ValueError occurs
d. TypeError occurs
a. invalid code
b. JavaTpoint has not exist
c. JavaTpoint has exist
d. none of these above
Explanation: A new exception class must inherit from a BaseException, and there is no such inheritance here.
z = {"x":0, "y":1}
a. x dictionary z is created
b. x and y are the keys of dictionary z
c. 0 and 1 are the values of dictionary z
d. All of the above