wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python_Mock

Total questions: 50

Worksheet time: 39mins

Name
Class
Date
1.
Which of the following is NOT a feature of Python?
a)
A. Platform independent
b)
B. Dynamically typed
c)
C. Manual memory management
d)
D. Interpreted Language
2.
Which of the following is an infinite loop in Python?
a)
A. while True:
b)
B. for i in range(1, 10, -1):
c)
C. while i > 0:
d)
D. Both A and C
3.
Which keyword is used to skip the current iteration of a loop?
a)
A. skip
b)
B. continue
c)
C. pass
d)
D. break
4.
How do you access the last character of a string s?
a)
A. s[-1]
b)
B. s[len(s)]
c)
C. s[len(s)-1]
d)
D. Both A and C
5.
What does the join() method do in threading?
a)
A. Joins two threads
b)
B. Waits for a thread to finish execution
c)
C. Merges thread results
d)
D. None of the above
6.
What does the items() method in Dictionary return?
a)
A. Keys of the dictionary
b)
B. Values of the dictionary
c)
C. Key-value pairs as tuples
d)
D. Items of dictionary
7.

How many times will the following loop execute?

a)
A. `3`
b)
B. `2`
c)
C. `1`
d)
D. `0`
8.
Which of these best describes polymorphism?
a)
A. The ability to define multiple classes
b)
B. The ability to take many forms
c)
C. The ability to override parent class attributes
d)
D. The ability to create private variables
9.

What is the result of this code snippet?

a)

A. Creates a new polygon for the geometry

b)

B. Clips the Raster based on the geometry

c)

C. Adds the geometry to the attribute table

d)

D. Calculates the geometry of the layer.

10.
What is the purpose of the __init__ method in a Python class?
a)
A. Destructor of a class
b)
B. Initializes class attributes when an object is created
c)
C. Used for static methods
d)
D. Handles object cleanup
11.
Which function returns all keys in a dictionary?
a)
A. dictionary.getkeys()
b)
B. dictionary.keys()
c)
C. dictionary.items()
d)
D. dictionary.values()
12.
What is a recursive function?
a)
A. A function that calls itself during execution
b)
B. A function that returns multiple values
c)
C. A function defined within another function
d)
D. A function that always executes in a loop
13.
Which of the following correctly defines a lambda function?
a)
A. lambda x, y: x + y
b)
B. lambda(x, y) { return x + y }
c)
C. def lambda(x, y): return x + y
d)
D. lambda x: x + y
14.
What does the return keyword do in a function?
a)
A. Terminates the function and optionally returns a value
b)
B. Loops the function call
c)
C. Converts local variables to global variables
d)
D. Defines a function
15.
What is the purpose of the try-except block?
a)
A. To avoid runtime errors
b)
B. To handle exceptions during program execution
c)
C. To terminate a program immediately when an exception occurs
d)
D. To debug the program
16.

Which of the following is one of the four OOP concepts? Select all the options Applicable

a)
A. Polymorphism
b)
B. Encapsulation
c)
C. Compilation
d)
D. Inheritance
17.

What are global variables in Python? Select all options applicable.

a)
A. Variables defined within a function
b)
B. Variables that can be accessed from anywhere in the program
c)
C. Variables defined in a specific block
d)
D. Variables declared with the global keyword
18.

What is the output of this code?

a)
A. `3`
b)
B. `4`
c)
C. `2`
d)
D. `Error`
19.
Why are nested if statements used?
a)
A. To check multiple independent conditions
b)
B. To evaluate hierarchical or dependent conditions
c)
C. To terminate a loop early
d)
D. To reduce the number of conditions
20.
What is the correct syntax to define a class in Python?
a)
A. class ClassName:
b)
B. class ClassName():
c)

C. def class ClassName:

d)
D. function className:
21.
How can you export a layout to PDF?
a)
A.  layout.exportToPDF()
b)
B.    layout.saveAsPDF()
c)
C.    layout.printToPDF()
d)
D.    layout.outputPDF()
22.
What does arcpy.sa.Aspect() calculate?
a)
A.    Slope direction from a DEM
b)
B.    Gradient of a raster
c)
C.    Cell classification by value
d)
D.    Raster extent
23.

The (a)   function in ArcPy is used to delete a feature class, table, or raster dataset.

24.
What is the purpose of arcpy.ListFields()?
a)

A.    Add list of new fields

b)
B.    Delete existing fields
c)
C.    List field names and properties
d)
D.    Alter field attributes
25.
How can you delete multiple fields in a feature class?
a)
A.    arcpy.RemoveFields()
b)
B.     arcpy.DeleteField_management()
c)
C.     arcpy.DeleteFields()
d)
D.    arcpy.RemoveField_management()
26.
Which function retrieves properties like the minimum and maximum values of a raster?
a)
A.       arcpy.GetRasterStats()
b)
B.        arcpy.sa.GetProperties()
c)
C.        arcpy.GetRasterProperties_management()
d)
D.       arcpy.RasterProperties()
27.
What is the purpose of arcpy.na.AddLocations()?
a)
A.    To solve the network layer
b)
B.    To add impedance to the layer
c)
C.    To add facilities and incidents
d)
D.    To create new travel routes
28.
What is the output of arcpy.sa.Reclassify()?
a)
A.    Vector features grouped into ranges
b)
B.    A classified raster with remapped values
c)
C.    An updated field in the input raster
d)
D.    New geometry objects from rasters
29.

What will the following snippet print?

a)
A.    Total area of the "Parks" feature class
b)
B.    The number of records in "Parks"
c)
C.    All field names in "Parks"
d)
D.    The total number of feature classes in the workspace
30.
Which function is used to create a "Closest Facility" Network Analyst layer?
a)
A.     arcpy.na.SolveClosestFacility()
b)
B.     arcpy.na.MakeClosestFacilityLayer()
c)
C.     arcpy.na.ClosestFacility()
d)
D.     arcpy.na.CreateFacilityLayer()
31.

What is the purpose of the else block in exception handling?

a)

A. Executes when the try block raises an exception

b)

B. Executes when the try block does not raise an exception

c)

C. Executes only after the finally block

d)

D. Executes if no exceptions are defined in the except block

32.
What is the purpose of arcpy.env.workspace?
a)
A.    To set the default location for saving outputs
b)
B.    To specify the working directory for tools and functions
c)
C.    To change the coordinate system of a feature class
d)
D.    To store feature classes temporarily
33.
Which function creates a buffer around features?
a)
A.    arcpy.Buffer_management()
b)
B.    arcpy.analysis.Buffer()
c)
C.    arcpy.sa.Buffer()
d)
D.    arcpy.management.MakeBuffer()
34.

What is the output of this code?

a)

A. [1, 4, 9, 16]

b)

B. (1, 4, 9, 16)

c)

C. [11, 22, 33, 44]

d)

D. [30]

35.
How do you reproject a feature class in ArcPy?
a)
A.    arcpy.sa.Reproject()
b)
B.    arcpy.analysis.Reproject()
c)
C.    arcpy.management.Project()
d)
D.    arcpy.mapping.Reproject()
36.
Which function joins attributes from one table to another?
a)
A.  arcpy.analysis.JoinAttributes()
b)
B.  arcpy.analysis.JoinField()
c)
C.  arcpy.management.JoinField()
d)
D.  arcpy.management.AddJoin()
37.

What is the difference between "is" and “==” ?

a)

A. 'is' checks equality of values, '==' checks memory location

b)

B. 'is' checks memory location, '==' checks equality of values

c)

C. 'is' and '==' are interchangeable

d)

D. 'is' compares types, '==' compares values

38.
Which of the following correctly converts a list of tuples into a dictionary?
a)
A. dict([(1, 'a'), (2, 'b')])
b)
B. dict({1: 'a', 2: 'b'})
c)
C. dict([1, 'a'], [2, 'b'])
d)
D. dict({(1, 'a'), (2, 'b')})
39.
What does the enumerate() function return?
a)
A. A dictionary of index-value pairs
b)
B. A list of index-value tuples
c)
C. An iterable of index-value pairs
d)
D. None of the above
40.
Which of the following is the most efficient way to iterate over both keys and values in a dictionary?
a)

A.

b)

B.

c)

C.

d)

D.

41.

What is the output of this code?

a)
A. [1, 4, 9, 16]
b)
B. (1, 4, 9, 16)
c)
C. [1, 2, 3, 4]
d)
D. Error
42.

Which exception is raised by this code?

print(int('xyz'))

a)
A. ValueError
b)
B. TypeError
c)
C. NameError
d)
D. IndexError
43.
What happens if an exception is not caught in Python?
a)
A. The program terminates with a traceback message
b)
B. The program continues execution
c)
C. Python raises a NotCaughtError
d)
D. None of the above
44.
What is the purpose of the else block in exception handling?
a)
A. Executes when the try block raises an exception
b)
B. Executes when the try block does not raise an exception
c)
C. Executes only after the finally block
d)
D. Executes if no exceptions are defined in the except block
45.
How do you define user-defined exceptions in Python?
a)

A. By inheriting from the Base class

b)
B. By inheriting from the Exception class
c)
C. Using the try block
d)
D. Python does not support user-defined exceptions
46.
What happens when you call list.clear()?
a)
A. Removes duplicate values from the list
b)
B. Removes all elements from the list
c)
C. Deletes the list variable entirely
d)
D. None of the above
47.

What is the result of the following code?

"hello".split("e")

a)
A. `['h', 'llo']`
b)
B. `['h', 'e', 'llo']`
c)
C. `['he', 'llo']`
d)
D. Error
48.
Which of the following methods converts a string to uppercase?
a)
A. string.uppercase()
b)
B. string.upper()
c)
C. string.toUpper()
d)
D. string.capital()
49.
What is the difference between sorted() and sort()?
a)
A. sort() modifies the original list; sorted() returns a new sorted list
b)
B. sorted() sorts in ascending order, while sort() does not
c)
C. sort() accepts fewer arguments than sorted()
d)
D. No difference
50.
What does the re.match() function do?
a)
A. Matches a pattern anywhere in the string
b)
B. Matches a pattern only at the beginning of the string
c)
C. Matches all occurrences of a pattern
d)
D. None of the above