Download as pdf or txt
Download as pdf or txt
You are on page 1of 72

Python Programming

semester (online) Test

First Name *

Sunday

Surname *

Bamidele

Other Name

Oluwatobiloba

Matriculation Number *

P/hd/23/3410007

Untitled Section
What does the operator // do in Python? *

Exponential

Floor division

Modulus

Bitwise AND

Which of the following best describes *


Polymorphism in object-oriented
programming?

The ability of a class to inherit from


multiple classes

The ability to define different methods


with the same name in different classes

The process of combining data and code


into a single unit

The feature that allows a single function


or method to operate on different types of
objects
Which phase occurs at runtime for *
interpreted languages but at compile time
for compiled languages?

Lexical analysis

Code generation

Syntax analysis

Execution

What is the primary purpose of *


Encapsulation in object-oriented
programming?

To enable code reuse through the creation


of new objects

To hide the implementation details and


expose only the essential features

To manage memory allocation in objects

To bundle data and methods that operate


on the data into a single unit
:
What does the << operator do in bitwise *
operations?

Right shift

Left shift

Bitwise AND

Bitwise OR

What is the primary purpose of the if *


statement in Python?

To declare a variable

To perform a conditional check

To create a loop

To define a function
:
In SQL, what is the purpose of the ORDER *
BY clause?

To group rows based on a specified


column

To filter records using a condition

To sort the result set in ascending or


descending order

To perform a join operation

When designing a recursive function, what *


is the significance of the "divide and
conquer" approach?

It involves dividing the problem into


smaller subproblems and solving them
independently

It requires using only the divide operator


(/) in the function

It means the function must always return


a boolean value

It implies using loops instead of recursion


:
What is the primary function of the Python *
PowerShell development environment?

Running Python scripts only

Running PowerShell scripts only

Enabling the integration of Python scripts


within the PowerShell environment

Creating a standalone Python


development environment

What is a function docstring used for in *


Python?

To declare variables

To create loops

To provide documentation for the function

To perform mathematical operations


:
What is the main advantage of *
Polymorphism in object-oriented
programming?

It allows a class to inherit from multiple


classes.

It hides the implementation details and


exposes only the essential features.

It enables code reuse through the creation


of new objects.

It promotes flexibility and the ability to


operate on different types of objects using
a single interface.

What is the primary scripting language of *


PowerShell?

Python

Bash

JavaScript

PowerShell
:
What is the primary purpose of methods in *
a class?

To define attributes of objects.

To create new instances of a class.

To bundle data and code.

To declare constants.

Which of the following accurately describes *


the role of an interpreter in an interpreted
language?

Converts source code to machine code


before execution.

Translates the entire program into


machine code in advance.

Executes the source code directly without


an intermediate machine code.

Converts the source code into bytecode


for execution.
:
What is a variable in programming? *

A constant value

A storage location with a specific name


and data type

A reserved keyword

A function parameter

What is a key advantage of interpreted *


languages over compiled languages?

Higher performance

Platform independence

Smaller executable file sizes

Better optimization opportunities


:
In SQL, what is the purpose of the COUNT() *
function?

To calculate the average value

To count the total number of rows

To find the minimum value

To perform a join operation

In Python, what is a module? *

A built-in data type

A collection of functions and variables


saved in a file

A mathematical operation

A type of loop
:
What is a Parent Class in object-oriented *
programming?

A class that has no attributes.

A class that inherits from another class.

A class that is instantiated to create


objects.

A class that contains only methods.

What does the SQL acronym "ACID" stand *


for in the context of database transactions?

Atomicity, Consistency, Isolation,


Durability

Association, Control, Indexing, Design

Aggregation, Calculation, Integration,


Division

Allocation, Composition, Inheritance,


Delegation
:
What is the purpose of the += operator in *
Python?

Addition assignment

Subtraction assignment

Multiplication assignment

Division assignment

Which SQL operator is used for pattern *


matching in a WHERE clause?

LIKE

MATCH

EQUALS

CONTAINS
:
How do you import a module named *
"example_module" in a Python script?

import example_module

include example_module

from example_module import *

use example_module

What SQL keyword is used to filter records *


in a SELECT statement?

LIMIT

WHERE

FILTER

HAVING
:
What is the primary purpose of a Parent *
Class in a class hierarchy?

To prevent the creation of objects.

To provide a blueprint for other classes.

To contain only static methods.

To encapsulate private attributes.

Which of the following statements is true *


regarding Abstraction?

Abstraction is primarily concerned with


bundling data and methods into a single
unit.

Abstraction allows a class to inherit from


multiple classes.

Abstraction involves creating a new class


from existing classes.

Abstraction hides the implementation


details and exposes only the essential
features.
:
What is a namespace collision in the *
context of modules?

A situation where two modules


complement each other

A conflict that occurs when two modules


have the same name or share variable
names

A collaboration between multiple modules

A feature that allows modules to share


variables seamlessly

In the context of Python, which library is *


often used for working with MongoDB?

pymongo

SQLite3

SQLAlchemy

psycopg2
:
How do methods contribute to the concept *
of encapsulation in object-oriented
programming?

By creating new instances of a class.

By defining attributes within a class.

By bundling data and code into a single


unit.

By declaring variables outside of a class.

What is the primary purpose of functions in *


Python?

To declare variables

To create loops

To perform mathematical operations

To organize and reuse code


:
In Python, what does the term "function *
signature" refer to?

The name of the function

The documentation of the function

The parameters and their types in a


function

The body of the function

Which of the following is true about variable *


names in Python?

Variable names can start with a number

Variable names are case-sensitive

Variable names cannot contain


underscores

Variable names must be declared before


use
:
Which of the following is NOT a feature of *
Python?

Multi-threading support

Dynamic typing

Built-in memory management

Explicit declaration of data types

How can you use a module in your Python *


script?

By importing it using the import statement

By defining it with the module keyword

By copying and pasting its code into your


script

By including it within a loop


:
Which data type is suitable for representing *
numbers with decimal points, such as 3.14?

Integer

Float

Complex

String

What is the key difference between a for *


loop and a while loop in Python?

for loops are used for counting, and while


loops are used for iterating over elements

for loops are more efficient than while


loops

for loops have a fixed number of


iterations, while while loops continue as
long as a specified condition is true

while loops can only be used with


numerical data
:
What SQL command is used to change data *
in an existing table?

MODIFY

CHANGE

ALTER

UPDATE

What is the primary purpose of Abstraction *


in object-oriented programming?

To hide the implementation details and


expose only the essential features

To enable code reuse through the creation


of new objects

To create instances of classes

To manage memory allocation in objects


:
In programming, what is the purpose of *
casting?

To confuse developers

To make variables constant

To convert between different data types

To declare variables

What is the result of the expression 15 | 7 in *


bitwise operations?

23

15
:
What is the result of the expression 5 + 3 * *
2?

16

11

13

26

Which data type is appropriate for *


representing both the whole and fractional
parts of a number?

Integer

Float

Complex

String
:
Which SQL command is used to grant *
privileges to a user?

ALLOW PRIVILEGES

GRANT PRIVILEGES

PROVIDE PRIVILEGES

GRANT ACCESS

What is the correct syntax for defining a *


function in Python?

function my_function():

def my_function{}:

define my_function():

func my_function():
:
What SQL command is used to remove a *
table from a database?

REMOVE TABLE

DELETE TABLE

DROP TABLE

ERASE TABLE

Which SQL command is used to delete *


records from a table?

REMOVE

DELETE

DROP

ERASE
:
Which SQL clause is used to combine rows *
from two or more tables based on a related
column between them?

CONNECT

LINK

JOIN

MERGE

In object-oriented programming, where are *


methods typically defined?

Outside of any class.

Within variables.

Inside a class.

In the global namespace.


:
Which of the following statements best *
describes the primary difference between
an interpreted language and a compiled
language?

Interpreted languages are executed line-


by-line, while compiled languages are
executed as a whole.

Interpreted languages are faster than


compiled languages.

Compiled languages are platform-


independent, while interpreted languages
are platform-specific.

Compiled languages require an interpreter,


while interpreted languages do not

What SQL function is used to find the *


maximum value in a column?

MAX()

MIN()

AVG()

SUM()
:
Inheritance in object-oriented programming *
involves:

Creating a new class from existing


classes, allowing the new class to inherit
properties and behaviors

Combining data and code into a single


unit

Hiding the implementation details and


exposing only the essential features

Creating multiple instances of a class

What SQL function is used to find the *


average value in a column?

AVG()

MEAN()

AVERAGE()

MID()
:
What is the result of the expression 5 & 3 in *
bitwise operations?

What is the primary purpose of the integer *


data type in programming?

To represent whole numbers

To store decimal numbers

To handle complex numbers

To store characters
:
What does the | operator represent in *
bitwise operations?

Bitwise OR

Bitwise AND

Bitwise XOR

Bitwise NOT

What is the data type used for storing *


sequences of characters, like "Hello,
World!"?

Integer

Float

Complex

String
:
What is a Child Class in object-oriented *
programming?

A class that has no methods.

A class that is inherited by another class.

A class that inherits from another class.

A class that cannot be instantiated.

What is the role of the elif statement in *


Python conditional blocks?

It is executed when the if condition is True

It is executed when the if condition is


False

It is executed when the preceding if or elif


condition is True

It is executed in all cases


:
What is the purpose of the return statement *
in a function?

To print a value

To stop the execution of the function

To return a value from the function

To define a new variable

In Python, what is the primary purpose of a *


for loop?

To perform a conditional check

To create a loop that repeats a block of


code a specified number of times

To define a function

To check if a variable exists


:
Which of the following is an example of *
explicit casting?

Automatically converting an integer to a


float

Converting a float to an integer using int()

Implicitly converting a string to a boolean

Assigning a value to a variable

What happens if a recursive function lacks *


a base case?

The function will execute indefinitely,


leading to a stack overflow

The function will terminate immediately

The function will return None

The function will raise an exception


:
What is the primary goal of Abstraction in *
object-oriented programming?

To hide the implementation details and


expose only the essential features.

To enable code reuse through the creation


of new objects.

To combine data and code into a single


unit.

To manage memory allocation in objects.

In a recursive function, what is the *


significance of the "divide and conquer"
approach?

It involves dividing the problem into


smaller subproblems and solving them
independently

It means the function must always return


a boolean value

It requires using only the divide operator


(/) in the function

It implies using loops instead of recursion


:
What is a method in the context of object- *
oriented programming?

A variable that holds data within a class.

A function that is defined outside of a


class.

A bundle of data and code.

A class constructor.

What is casting in programming? *

Fishing for errors in code

Converting a variable from one data type


to another

Assigning values to variables

Writing code in a scripted language


:
What SQL command is used to add a new *
column to an existing table?

ALTER TABLE

ADD COLUMN

MODIFY TABLE

INSERT COLUMN

Which of the following statements about *


Python's garbage collection is true?

Python uses manual memory


management

Python relies on the programmer to free


memory explicitly

Python has an automatic garbage


collector

Python doesn't deallocate memory


:
What does the break statement do in a loop *
construct?

Continues to the next iteration of the loop

Ends the loop prematurely

Skips the current iteration and moves to


the next

Checks the loop condition

How does Inheritance contribute to code *


reuse in object-oriented programming?

By allowing a class to inherit from multiple


classes.

By combining data and code into a single


unit.

By creating new classes from existing


classes, inheriting their properties and
behaviors.

By hiding the implementation details and


exposing only the essential features.
:
In Python, what is the result of the *
expression True and False?

True

False

None

Error

Which SQL command is used to create a *


new database?

CREATE DATABASE

CREATE TABLE

INSERT INTO

ALTER DATABASE
:
What SQL command is used to update *
records in a table?

ALTER

MODIFY

UPDATE

CHANGE

When might you use the else statement in a *


conditional block?

When there is only one possible condition

When there are multiple conditions, and


you want a default action

When you want to create a loop

When you want to define a function


:
In terms of debugging, which type of *
language typically provides easier
debugging capabilities?

Compiled languages

Interpreted languages

Both have similar debugging capabilities

It depends on the specific programming


environment

What is the purpose of the Invoke- *


Expression cmdlet in PowerShell?

To execute Python expressions

To invoke external commands

To evaluate arithmetic expressions

To define custom functions in PowerShell


:
What is the base case in a recursive *
function?

The first line of code in the function

A condition that prevents the function


from calling itself infinitely

The last line of code in the function

A condition that ensures the function


returns a value

How can you access a function named *


"calculate" from a module named
"math_operations"?

math_operations.calculate

calculate.math_operations

import math_operations.calculate

from math_operations import calculate


:
Which SQL command is used to create an *
index on a table?

ADD INDEX

CREATE INDEX

MAKE INDEX

INDEX TABLE

What does the range() function often *


contribute to in a for loop?

Ending the loop

Providing the number of iterations

Checking a condition

Enumerating elements
:
What is the term used to describe the *
process by which a Child Class can provide
its own implementation of a method
inherited from the Parent Class?

Class cloning.

Class encapsulation.

Class overriding.

Class instantiation.

How can you call a PowerShell command *


from a Python script?

Using the bash module

Using the subprocess module

Using the powershell module

PowerShell commands cannot be called


from Python
:
What is the primary advantage of using *
recursive functions?

They are more efficient than iterative


solutions

They are easier to write and understand

They allow for concise and elegant


solutions to certain problems

They eliminate the need for conditional


statements

What is a recursive function in Python? *

A function that performs mathematical


operations

A function that calls itself during its


execution

A function that uses loops extensively

A function with no parameters


:
Which of the following statements is true *
about casting?

Casting is only necessary for string


variables

Casting can result in loss of data


precision

Casting is a synonym for variable


declaration

Casting is only applicable in compiled


languages

What is the SQL command for creating a *


new table in a database?

CREATE TABLE

CREATE DATABASE

INSERT INTO

ALTER TABLE
:
What does the type() function in Python do? *

It performs mathematical calculations

It checks the data type of a variable or


value

It creates a new instance of a class

It prints text to the console

Which of the following databases is *


commonly used with Python through
libraries like pymysql and MySQLdb?

MongoDB

SQLite

PostgreSQL

MySQL
:
In a while loop, what is the condition that *
determines whether the loop continues or
terminates?

The number of iterations

The presence of the break statement

The value returned by the loop

A specified condition

What does "Pythonic" code refer to? *

Code written in CPython

Code following Python conventions and


idioms

Code using only Python built-in functions

Code with extensive use of Python


comments
:
What is a default parameter in a Python *
function?

A parameter that must be provided by the


caller

A parameter with a predefined value, used


if no value is provided by the caller

A parameter that is optional and can be


omitted

A parameter that is automatically


generated by Python

What is a base case in a recursive function? *

The first line of code in the function

A condition that prevents the function


from calling itself infinitely

A mathematical operation

A variable used in the recursive call


:
What does Encapsulation help achieve in *
object-oriented programming?

Flexibility in operating on different types


of objects

Code reuse through the creation of new


objects

Hiding the implementation details and


exposing only the essential features

Enabling a class to inherit from multiple


classes

Which concept in object-oriented *


programming promotes the idea of creating
new classes from existing classes,
inheriting their properties and behaviors?

Encapsulation

Abstraction

Polymorphism

Inheritance
:
What is a module in Python? *

A graphical user interface (GUI)

A built-in function

A collection of functions and variables


bundled together in a file

A type of loop

In Python, how is a complex number *


represented?

5.2

"Hello"

3 + 4j

'123'
:
What is a "method" in the context of Object- *
Oriented Programming?

A function that is defined outside of a


class.

A variable that holds data within a class.

A bundle of data and code.

A function that is defined within a class.

What is the role of the call stack in the *


execution of recursive functions?

What is the purpose of the len() function


in Python?

It calculates logarithms

It measures the length of a sequence or


collection

It converts values to lowercase

It generates random numbers


:
What is the purpose of the GROUP BY *
clause in SQL?

To sort records in ascending order

To group rows based on a specified


column

To filter records using a condition

To perform arithmetic operations on


numeric columns

Which Python library provides support for *


interacting with SQLite databases?

SQLAlchemy

SQLite3

psycopg2

pymongo
:
What is the purpose of PEP 8 in Python? *

Python Enhancement Proposal for new


features

Python Enhancement Proposal for bug


fixes

Python Enhancement Proposal for code


style conventions

Python Enhancement Proposal for


performance optimization

What is a function parameter in Python? *

A variable declared inside a function

A value passed to a function when it is


called

The return value of a function

A condition within a function


:
What is implicit casting? *

Casting that requires explicit conversion


functions

Casting that happens automatically


without the programmer's intervention

Casting that only works for strings

Casting that involves complex


mathematical operations

The psycopg2 library is commonly used to *


connect Python applications to which type
of database?

SQLite

MySQL

PostgreSQL

MongoDB
:
What is a key characteristic of recursive *
functions in Python?

They always use loops instead of


recursion

They have a fixed number of iterations

They call themselves during their


execution

They only work with integers

Which concept in object-oriented *


programming is related to combining data
and code into a single unit?

Abstraction

Polymorphism

Inheritance

Encapsulation
:
Which of the following best describes the *
concept of Polymorphism?

Creating a new class from existing


classes, allowing the new class to inherit
properties and behaviors.

Combining data and code into a single


unit.

The ability to define different methods


with the same name in different classes.

Hiding the implementation details and


exposing only the essential features.

What does the >> operator do in bitwise *


operations?

Left shift

Right shift

Bitwise AND

Bitwise XOR
:
How are methods related to objects in a *
class?

Methods are variables within a class.

Objects are methods that operate on data.

Methods define the attributes of objects.

Methods are functions associated with


objects, allowing them to perform actions
and manipulate data.

What does the in operator check for in *


Python?

Object identity

Object membership in a sequence

Object equality

Object non-membership
:
In the context of Inheritance, what is a *
"subclass" or "derived class"?

The class from which another class


inherits properties and behaviors.

A class that inherits from multiple


classes.

The class that is used to create objects.

The class that inherits properties and


behaviors from another class.

Which of the following databases can be *


accessed using the cx_Oracle library in
Python?

Oracle Database

MongoDB

MySQL

SQLite
:
What is the role of the SQL ROLLBACK *
statement?

To commit changes made during a


transaction

To permanently save changes made


during a transaction

To undo changes made during a


transaction

To retrieve data from a database

In SQL, what is the purpose of the SELECT *


statement?

To update records

To insert records

To retrieve data from a database

To delete records
:
Which Python library function is used to *
open and read the contents of a file?

read_file()

open_file()

file_read()

open()

What is the purpose of the __init__.py file in *


a directory containing Python modules?

It is required for every Python script

It signals that the directory contains


Python modules and should be treated as
a package

It contains the main code of the module

It is optional and has no specific purpose


:
Which SQL keyword is used to retrieve *
distinct values in a SELECT statement?

DIFFERENT

DISTINCT

UNIQUE

DISTINCTIVE

What is the result of the expression 8 ^ 3 in *


bitwise operations?

11

24

0
:
Which SQL command is used to insert data *
into a table?

INSERT INTO

CREATE TABLE

SELECT

UPDATE

What SQL command is used to revoke *


privileges from a user?

DENY PRIVILEGES

REMOVE PRIVILEGES

REVOKE

DISALLOW ACCESS
:
In a series of if, elif, and else statements, *
how many blocks of code will be executed
at most?

One

Two

Three

All of them

Which of the following is a key feature of *


Python?

Static Typing

Strong Typing

Explicit Typing

Dynamic Typing
:
In SQL, what clause is used to sort the *
result set of a SELECT statement?

SORT BY

ORDER BY

GROUP BY

ARRANGE BY

Which function is used to convert a string *


to an integer in Python?

int()

str()

float()

convert_int()
:
Which command in PowerShell allows the *
execution of Python scripts?

run-python

execute-python

python

Start-Process python

What happens if none of the conditions in *


an if, elif, else block evaluates to True?

The else block is executed

The program terminates with an error

No block is executed

All blocks are executed


:
What does the ~ operator do in bitwise *
operations?

Bitwise OR

Bitwise AND

Bitwise NOT

Bitwise XOR

What is a "base class" or "parent class" in *


the context of Inheritance?

The class that inherits properties and


behaviors from another class.

A class that is used to create objects.

The class from which another class


inherits properties and behaviors.

A class that bundles data and methods


into a single unit.
:
What does the ^ operator represent in *
bitwise operations?

Bitwise OR

Bitwise AND

Bitwise XOR

Bitwise NOT

What is the purpose of the max() function *


in Python?

It finds the smallest element in a list

It calculates the average of a set of


numbers

It returns the maximum value from a


sequence

It generates a random number


:
Which of the following is a valid function *
name in Python?

123_function

my function

my_function_2

def_function

What is the purpose of the is operator in *


Python?

Checks if two values are equal

Checks if two values are not equal

Checks if two values refer to the same


object

Performs bitwise AND


:
What happens if a recursive function lacks *
a base case?

The function will execute indefinitely,


leading to a stack overflow

The function will terminate immediately

The function will raise an exception

The function will return None

What is the purpose of the SQL COMMIT *


statement?

To delete records from a table

To permanently save changes made


during a transaction

To retrieve data from a database

To roll back a transaction


:
What is the scope of a variable in *
programming?

The range of values a variable can take

The lifetime of a variable

The part of the program where the


variable can be accessed

The data type of a variable

What does the != operator signify in *


Python?

Greater than

Not equal to

Less than or equal to

Equal to
:
What is the primary purpose of the def *
keyword in Python?

To declare a variable

To create a loop

To define a function

To perform mathematical operations

Which of the following is a valid variable *


name in Python?

123variable

_myVar

break

TrueValue
:
What is the purpose of the return statement *
in a function?

To print a value

To stop the execution of the function

To return a value from the function

To define a new variable

How does a Child Class relate to a Parent *


Class in object-oriented programming?

The Child Class is a duplicate of the


Parent Class.

The Child Class inherits attributes and


methods from the Parent Class.

The Child Class cannot access methods


of the Parent Class.

The Child Class overrides the Parent Class


completely.
:
What is the purpose of assigning a value to *
a variable?

To reserve memory for the variable

To declare the variable's data type

To initialize the variable with a specific


value

To make the variable constant

This content is neither created nor endorsed by Google. Report


Abuse - Terms of Service - Privacy Policy

Forms
:

You might also like