4-Python Programming Mcqs With Answers PDF
4-Python Programming Mcqs With Answers PDF
WWW.PAKISTANBIX.COM
Pakistanbix.com is an online test preparation website where aspirants can prepare themselves for
all types of entry tests. Users can prepare themselves for CCS, PMS, PPSC, FPSC, BPSC, SPSC,
KPPSC, AJKPSC, NTS, PTS, Headmaster, Lecturer, SST and types of exams. Here users can see
all subjects Mcqs, Daily Current Affairs, Daily Dawn Vocabulary, Online tests/Quiz, Past Papers,
PDF Notes of All Subjects and allothers valueable Data.
All subjects PDF notes are posted here in this section. Users can read all the pdf notes
online or they have choice to download these notes in the the form of Pdf. General
knowledge, Pakistan Affairs, Islamic Studies, English, Everyday Science, Urdu, Maths,
Current Affairs, Pedagogy, Biology, Chemistry, Physics and all subjects pdf notes are
available here. Aspirants of CSS, PMS, FPSC, PPSC, AJKPSC, KPPSC, BPSC, SPSC,
NTS, PTS, OTS, Lecturer, Headmaster, Educators etc can download all material in pdf
form from here.
A. 23 23
B. 23 32
C. 32 32
D. None of Above
Answer: B
10. list, tuple dictionary are which types of Data Types.
A. Binary Types
B. Boolean Types
C. Sequence Types
D. None of the above
Answer: C: Sequence Types
11. Which types of logical operators in Python?
A. AND
B. OR
C. NOT
D. All of the above
Answer: D: All of the above
12. What is the name of the operator ** in Python?
A. Exponentiation
B. Modulus
C. Floor division
D. None of the these
Answer: A: Exponentiation
13. What is the output of following code?
x="Ram, Shya"
print(x[::5]
A. RS
B. RAMSH
C. RAM
D. SHYAM
Answer: A: RS
14. What is the extension of Python Program?
A. .execute python
B. .python
C. .py
D. .run python
Answer: C: .py
15. Which keyword used in python language?
A. finally
B. lambda
C. while
D. All of Above
Answer: D: All of Above
16. Which return the % operator?
A. Quotient
B. Divisor
C. Remainder
D. Multiplication
Answer: C: Remainder
17. What is the maximum possible length of an identifier?
A. 31 characters
B. 63 characters
C. 79 characters
D. 69 characters
Answer: C: 79 characters
18. Which are methods of list?
A. append()
B. extend()
C. insert()
D. All of the above
Answer: D: All of the above
19. The list.pop ([i]) is used for removing the item at the given position in the list?
A. Yes
B. No
Answer: A: Yes
20. What is the output of following program?
r = lambda q: q * 2
s = lambda q: q * 3
x=2
x = r(x)
x = s(x)
x = r(x)
print (x)
A. 4
B. 12
C. 24
D. None of Above
Answer: C: 24
21. What is the output of following program?
a = 4.5
b=3
print (a//b)
A. 1.0
B. 2.0
C. 0
D. None of Above
Answer: A: 1.0
22. What is the output of following program?
a = True
b = False
c = False
if a or b and c:
print ("CAREERBODHSANSTHAN")
else:
print ("careerbodh")
A. CAREERBODHSANSTHAN
B. Careerbodh
C. CAREERBODHSANSTHAN Careerbodh
D. None of Above
Answer: A
23. Python is.........
A. Programming Language
B. Web browser
C. Malware
D. Operating System
Answer: A
24. Python Dictionary is used to store the data in
A. Key value pair
B. set value pair
C. tuple value pair
D. None of the above
Answer: A:
25. Which is invalid variable?
A. my_string_1
B. _
C. Foo
D. 1st_string
Answer: D
26. What is the output of given code?
4+2**5//10
A. 77
B. 7
C. 3
D. 0
Answer: B
27. The Python language developed in which?
A. 1995
B. 1989
C. 1972
D. 1981
Answer: B
28. What do we use to define a block of code in Python language?
A. Key
B. Indentation
C. Brackets
D. All of above
Answer: B
29. Single line comment in python?
A. /
B. //
C. #
D. !
Answer: C
30. What is the output of below program?
count = 1
def careerbodh():
global count
for i in (1, 2, 3):
count += 1
careerbodh()
print (count)
A. 1
B. 2
C. 3
D. 4
Answer: D
31. Conditional statements are also known as
A. Decision-making
B. Array
C. List
D. Looping
Answer: A:
32. What is output of below code?
for i in range(2):
print (i)
for i in range(4,5):
print (i)
Answer:
0
1
4
33. Which is not used as conditional statement in Python?
A. switch
B. if...else
C. elif
D. for
Answer: A
34. The return value for trunc() is:
A. bool
B. float
C. int
D. string
Answer: C
35. What is the output of below code?
print(2**3 + (2+ 6)**(1 + 1))
A. 72
B. 18
C. 22
D. None of Above
Answer: 72
36. What is the output of below program?
var = 10
print(type(var))
var = "Ram"
print(type(var))
A. str and int
B. int and str
C. int and int
D. str and str
Answer: B
37. Is Python programming compiled or interpreted?
A. Python program is both compiled and interpreted
B. Python program is neither compiled nor interpreted
C. Python program is only compiled
D. Python program is only interpreted
Answer: B
38. What is the output of below code?
a = "Careerbodh"
b = 13
print (a + b)
A. Careerbodh
B. 13
C. Careerbodh13
D. Error
Answer: D
39. Nested if Statements represents?
A. if statement inside another if statement
B. if statement outside the another if statement
C. Both A and B
D. None of the above
Answer: A
40. Which statements is correct about the object-oriented programming concept
in Python?
A. pop
B. remove
C. dispose
D. discard
Answer: A
47. In Python, the break and continue statements, together which are called….
A. Jump
B. goto
C. compound
D. break
Answer: B
48. The output of below Python code -
x={1:”X”,2:”Y”,3:”Z”}
del x
A. the del method does not exist for dictionary
B. the del would delete the values present in dictionary
C. the del would delete all the keys in dictionary
D. the del would delete the entire dictionary
Answer: C
49. Which declarations is incorrect?
A. _x = 1
B. __b = 9
C. __xy__ = 7
D. None of Above
Answer: D
50. Which not a keyword in Python language?
A. val
B. raise
C. try
D. with
Answer: A
51. The output of below Python program is
sum(1,3,3)
sum([2,5,6])
A. 7, 13
B. Error, Error
C. Error, 13
D. 7, Error
Answer: C
52. The output of below Python program:
def find(a, **b):
print(type(b))
find(‘letters’,a=’1′,b=’2′)
A. An exception is thrown
B. String
C. Dictionary
D. Tuple
Answer: C
print(len(list(map(list, x)))))
A. 1
B. 2
C. Error
D. Not specified
Answer: C
55. In Python, the primary use of the tell() method is that:
A. within the file, it tells the current position
B. within the file, it tells the end position
C. it tells us if the file is opened
D. none of the above
Answer: A
56 - What is output of below python code:
str = ['career', 'bodh', 'snasthan']
' '.join(str)
A. ['careerbodhsansthan']
B. ' careerbodhsansthan '
C. [' career bodh sansthan ']
D. ' career bodh sansthan '
Answer: B
57. False statement in python
A. int(256)== 256
B. int('256')== 256
C. int(256.0)== 256
D. None of the these
Answer: D
Answer: D
59. Let two sets X & Y, then X<Y is:
A. True if len(X) is less than len(Y).
B. True if the elements in X when compared are less than the elements in Y.
C. True if X is a proper subset of Y.
D. True if X is a proper superset of Y.
Answer: C
60. What is the output of the following code?
Q1. Which is the following number can never be generated by the following code:
random.randrange(0,50)
A. 0
B. 1
C. 49
D. 50
Answer: 50
A. True
B. False
C. Sometimes
D. Never
Answer: B
A. Unlimited length
B. Limited length
Answer: A
A. True
B. Flase
C. Can’t s say
D. May be
Print(np.minimum([2,3,4],[1,5,2]))
A. [1 2 5]
B. [1 5 2]
C. [2 3 4]
D. [1 3 2]
Answer: D
A=[5,’abc’,3,2,6]
A. Tuple
B. Array
C. List
D. Dictionary
Answer: C
Q7. Flowcharts and algorithms are used for
A. Better programming
B. Efficient coding
Answer: D
for i in range(20,30,10):
j=i/2
print(j)
A. 10 15
B. 10.0 15.0
C. 10.0
D. None of these
Answer: C
Q9. Method which uses a list of well defined instructions to complete a task
starting from a given initial state to end state is called as----------
A. Program
B. Algorithm
C. Flowchart
D. Both A and C
Answer: B
A. Line
B. Arrow
C. Process
D. Box
Answer: B
Q11. ---------------------- scans the entire program and translates it as a whole into
machine code.
A. Compiler
B. Interpreter
C. Debugger
D. None of Above
Answer: A
print(message*times)
say('Hello')
say('World',5)
A. Hello
WorldWorldWorldWorldWorld
B. Hello
World5
C. Hello
World,World,World,World,World
D. Hello
HelloHelloHelloHelloHello
Answer: A
Q13. The action performed by a -------structure must eventually cause the loop to
terminate.
A. Sequence
B. Process
C. Repetition
D. Case
Answer: C
a=true
b=false
c=false
if a or b and c:
print("HELLO")
else:
print ("hello")
A. HELLO
B. Hello
C. HellO
D. None of these
Answer: A
A. Numbering Python
B. Number in Python
C. Numerical Python
D. None of these
Answer: C
A. Queue
B. Macro
C. Micro
D. Union
Answer: B
Q17. Which statement will move file pointer 10 bytes backward from current
position?
A. f.seek(-10,0)
B. f.seek(-10,1)
C. f.seek(10,0)
D. None of above
Answer: A
Q18. Choose the answer for statement 1
Import-----------------------# statement 1
Rect=[]
While True:
m=int(input(“Enter”))
nm=input(“Enter”)
Temp=[m,nm]
Rect.append(temp)
Ch=input(“Enter choice(Y?N”)
If ch.upper==”N”:
Break
F=open(stud.dat”,”--------------------------“) #statement 2
------------------------------.dump(rec,f) #statement 3
-----------------.close() #statement 4
A. csv
B. load
C. pickle
D. unpickle
Answer: C
D. All of mentions
Answer: A
Q20. What is the output of following code?
A=[[1,2,3],
[4,5,6],
[7,8,9]]
print(A[1][:])
A. [1,2,3]
B. [4,5,6]
C. [2,5,8]
D. None of these
Answer: B
import numpy as np
a=np.array([1,2,1,5,8])
b=np.array([0,1,5,4,2])
c=a+b
c=c*a
print(c[2])
A. 6
B. 10
C. 0
D. None of these
Answer: A
A. Circles
B. Boxes
C. Arrows
D. Line
Answer: B
Q23.In Python, which of the following functions is a built-in function?
A. val()
B. print()
C. func_k()
D. None of these
Answer: B
Q24. Which mode creates a new line file if the file does not exist?
A. Write mode
B. Append mode
C. Both A & B
Answer: C
Q25. What is the output of the following code?
import numpy as np
a=np.array([[1,2,3])
print(a.ndim)
A. 1
B. 2
C. 3
D. 0
Answer:B
A. Denoted by triple quotes for providing the specification of certain program elements
Answer: D
a=15
b=6
print(a and b)
print(a or b)
A. True True
B. False False
C. 6 15
D. 15 6
Answer: C
A. Break
B. Continue
C. Pass
D. None of these
Answer: A
Q29. Identity the correct function header.
A. def fun(a=2,b=3,c)
B. def fun(a=2,b,c=3)
D. def fun(a,b,c=3,d)
Answer: C
B. C++
C. Java
D. None of these
Answer: A
def func(a,b=5,c=10):
func(3,7)
func(25,c=24)
func(c=50,a=100)
A. a is 3 and b is 7 and c is 10
a is 25 and b is 5 and c is 24
B. a is 3 and b is 7 and c is 10
a is 5 and b is 25 and c is 24
C. a is 7 and b is 3 and c is 10
a is 25 and b is 5 and c is 24
D. None of these
Answer: A
A. True
B. False
C. Can’t say
D. May be
Answer: B
Q33.What will be the output of the following algorithm for a=5, b=8, c=6?
Step 1: Start
Step 2: Declare variable a, b and c.
Step 4:
if a>b
if a>c
Else
Else:
If b>c
Else
Step 5: stop
D. Stop
Answer: A
import numpy as np
a=np.array([1.1,2,3])
print(a.dtype)
A. int32
B. float64
C. float
D. None of these
Answer: B
Import-----------------------# statement 1
Rect=[]
While True:
m=int(input(“Enter”))
nm=input(“Enter”)
Temp=[m,nm]
Rect.append(temp)
Ch=input(“Enter choice(Y?N”)
If ch.upper==”N”:
Break
F=open(stud.dat”,”--------------------------“) #statement 2
------------------------------.dump(rec,f) #statement 3
-----------------.close() #statement 4
A. F
B. Rec
C. File
D. Stud
Answer: A
Q36. Which of the following is not the built in function?
A. Input()
B. Tuple()
C. Print()
D. Dictionary()
Answer: D
Import math
abs(math.sqrt(36))
A. Error
B. 6
C. -6
D. 6.0
Answer: D
Answer: C
import numpy as np
a=np.array([11,2,3])
print(a.min())
A. 2
B. 1
C. 11
D. 3
Answer: A
A. Class Diagram
B. Code Comment
C. Use Case
D. Installation Guide
Answer: D
9). Which of the following will print the pi value defined in math module?
(a). print(pi)
(b). print(math.pi)
(c). from math import pi print(pi)
(d). from math import pi print(math.pi)
Answer-(c)
10). Packages modules import operator python used
(a). * (b). .
(c). -> (d). &
Answer-(b)
11). Function define
(a). module
(b). class
(c). Another function
(d). All of the above
Answer-(d)
12). Python lambda function
(a). true
(b). false
(c). Lambda is a function in python but user can is it.
(d). None of the above
Answer-(a)
13). What is a variable defind outside a function referred to as?
(a). local variable
(b). global variable
(c). static variable
(d). None of above
Answer-(b)
14). What is the output of following program
Z=lambda x:x*x
Print(z(6))
(a). 6 (b). 36 (c). 0 (d). error
Answer-(b)
15). What is the output of below python program.
(a). a
(b). A
(c). 97
(d). error
Answer-(a)
16). How is a function declared in python?
(a). def function function_name():
(b). declared function function_name()
(c). def function_name()
(d). declare function_name()
Answer-(c)
GK Mcqs: https://www.pakistanbix.com/category/general-knowledge-mcqs/