wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python and SQL Quiz

Total questions: 100

Worksheet time: 50mins

Name
Class
Date
1.

What is the output of print(type(5))?

a)

b)

c)

d)

2.

Python is a:

a)

Compiled Language

b)

Markup Language

c)

Low-level Language

d)

Interpreted Language

3.

Which of the following is a valid variable name in Python?

a)

1name

b)

name_1

c)

class

d)

first-name

4.

What is the result of int('5.3')?

a)

5

b)

Error

c)

5.3

d)

None

5.

What will type(3.0) return?

a)

int

b)

float

c)

double

d)

decimal

6.

Which keyword is used to define a function in Python?

a)

func

b)

define

c)

def

d)

function

7.

What is the output of: x = 10 if x > 5: print("High") else: print("Low")

a)

Low

b)

High

c)

10

d)

None

8.

Which loop is used to iterate over a sequence?

a)

if

b)

switch

c)

for

d)

do

9.

How many times will this loop run? for i in range(3): print(i)

a)

2

b)

3

c)

4

d)

Infinite

10.

Which statement breaks out of the loop?

a)

stop

b)

end

c)

break

d)

exit

11.

Which of the following is a valid while loop?

a)

while x < 10:

b)

until x > 10:

c)

loop x in range(10):

d)

when x < 10 do:

12.

Nested loops are:

a)

Invalid in Python

b)

Used to call functions

c)

Loops inside loops

d)

Only for strings

13.

Which keyword is used to return a value from a function?

a)

break

b)

continue

c)

return

d)

output

14.

Default arguments in Python are defined:

a)

Before the required arguments

b)

After the required arguments

c)

Anywhere

d)

In the function name

15.

What does recursion mean?

a)

Loop inside a loop

b)

A function calling itself

c)

Infinite loop

d)

None

16.

How can you import a module in Python?

a)

use math

b)

require(math)

c)

import math

d)

load(math)

17.

Which of the following is a built-in function?

a)

sum()

b)

append()

c)

insert()

d)

mapreduce()

18.

What does dir() do?

a)

Lists all files

b)

Lists methods and attributes of an object

c)

Creates a directory

d)

Deletes a file

19.

Which data structure is immutable?

a)

List

b)

Set

c)

Tuple

d)

Dictionary

20.

How do you define a dictionary?

a)

{}

b)

[]

c)

()

d)

<>

21.

What is the output of: len([1, 2, 3])?

a)

2

b)

3

c)

1

d)

Error

22.

How do you add an element to a set?

a)

add()

b)

append()

c)

insert()

d)

push()

23.

What is the key-value pair structure of a dictionary?

a)

(key, value)

b)

[key => value]

c)

{key: value}

d)

24.

Which one is a mutable data structure?

a)

Tuple

b)

List

c)

str

d)

int

25.

What mode is used to read a file?

a)

'w'

b)

'r'

c)

'a'

d)

'x'

26.

What does open('file.txt', 'w') do?

a)

Reads file

b)

Appends file

c)

Overwrites or creates file

d)

Deletes file

27.

Which module is used for JSON in Python?

a)

csv

b)

json

c)

data

d)

os

28.

What is used to catch exceptions in Python?

a)

try-except

b)

catch

c)

error handling

d)

raise-catch

29.

Which keyword is used to raise exceptions manually?

a)

error

b)

raise

c)

throw

d)

except

30.

What is a custom exception?

a)

Built-in error

b)

Error ignored

c)

User-defined error class

d)

None

31.

What is a class in Python?

a)

A blueprint for creating objects

b)

A function

c)

A module

d)

An attribute

32.

What is an object in Python?

a)

A type of loop

b)

A variable

c)

An instance of a class

d)

A keyword

33.

Which keyword is used to define a class?

a)

def

b)

class

c)

object

d)

module

34.

What is the purpose of the __init__ method?

a)

To create functions

b)

To initialize object state

c)

To call other classes

d)

To destroy the object

35.

What is inheritance?

a)

Copying code

b)

Accessing modules

c)

Deriving a class from another

d)

Using functions

36.

Which class is inherited?

a)

Base class

b)

Subclass

c)

Abstract class

d)

Object class

37.

What is encapsulation?

a)

Writing loops

b)

Combining data and methods in one unit

c)

Calling multiple functions

d)

None

38.

Which access modifier makes an attribute private?

a)

_name

b)

__name

c)

name

d)

public name

39.

What is polymorphism?

a)

Many methods with same name but different behavior

b)

One function

c)

Many classes with one method

d)

No method

40.

Method overriding happens in:

a)

Same class

b)

Different classes (child overrides parent)

c)

Only modules

d)

None

41.

Which method is called when an object is deleted?

a)

__del__()

b)

__destroy__()

c)

__end__()

d)

__exit__()

42.

How do you achieve abstraction in Python?

a)

Using interfaces

b)

Using abstract keyword

c)

Using abc module and abstract classes

d)

Using private methods

43.

Which SQL statement is used to retrieve data?

a)

GET

b)

SELECT

c)

FETCH

d)

EXTRACT

44.

What does the WHERE clause do?

a)

Deletes data

b)

Filters data

c)

Sorts data

d)

Creates table

45.

What is a primary key?

a)

A unique identifier

b)

A foreign reference

c)

A table name

d)

A row number

46.

Which SQL clause is used to combine rows from two or more tables?

a)

GROUP

b)

JOIN

c)

MERGE

d)

BIND

47.

What does ORDER BY do?

a)

Filters rows

b)

Groups rows

c)

Sorts rows

d)

Deletes rows

48.

Which join returns only matching records from both tables?

a)

LEFT JOIN

b)

RIGHT JOIN

c)

FULL JOIN

d)

INNER JOIN

49.

Which command is used to add a new row?

a)

ADD

b)

INSERT

c)

PUSH

d)

SAVE

50.

How do you delete data from a table?

a)

REMOVE

b)

DROP

c)

DELETE

d)

ERASE

51.

Which statement is used to modify existing data?

a)

UPDATE

b)

MODIFY

c)

CHANGE

d)

ALTER

52.

What does the ALTER command do?

a)

Change table structure

b)

Modify rows

c)

Rename database

d)

View data

53.

Which DBMS is open-source and widely used?

a)

Oracle

b)

MySQL

c)

MS Access

d)

SQL Server

54.

What is a foreign key?

a)

Unique identifier in a table

b)

A field that references a primary key in another table

c)

Duplicate of primary key

d)

A system column

55.

Which library is used to connect Python with MySQL?

a)

sqlite3

b)

mysql.connector

c)

pandas

d)

pyconnect

56.

What method is used to execute a query?

a)

run()

b)

execute()

c)

send()

d)

query()

57.

What method is used to execute a query?

a)

run()

b)

execute()

c)

send()

d)

query()

58.

What is required to connect Python with MySQL?

a)

Only username

b)

Only database

c)

Host, username, password, database

d)

Table only

59.

What is the best way to store student records in a CLI app?

a)

Dictionary

b)

Text file

c)

SQL table

d)

List

60.

CRUD stands for:

a)

Create, Remove, Use, Drop

b)

Create, Read, Update, Delete

c)

Create, Run, Update, Delete

d)

Check, Read, Use, Delete

61.

What does the commit() function do in database operations?

a)

Rollback

b)

Save changes

c)

Exit the app

d)

Clear screen

62.

What does HTTP stand for?

a)

Hyperlink Text Transfer Protocol

b)

Hyper Text Transfer Protocol

c)

High Text Transfer Protocol

d)

Hyper Tool Transfer Protocol

63.

Which of the following is a valid HTTP method?

a)

FETCH

b)

CONNECT

c)

GET

d)

LINK

64.

What does a client send to a server to request a resource?

a)

URL

b)

HTTP Request

c)

Web socket

d)

JSON

65.

What is the purpose of routing in web development?

a)

Redirect URLs

b)

Define how a server responds to a client request

c)

Secure the application

d)

Log the data

66.

Flask is a:

a)

Web server

b)

Python framework

c)

Database

d)

Markup language

67.

What decorator is used to define a route in Flask?

a)

@app.run()

b)

@route()

c)

@app.route()

d)

@flask.route

68.

Which function starts the Flask server?

a)

run()

b)

start()

c)

serve()

d)

launch()

69.

Jinja2 is used for:

a)

Writing backend code

b)

Writing CSS

c)

Writing templates

d)

Connecting to DB

70.

What method is commonly used for submitting form data securely?

a)

GET

b)

POST

c)

PUSH

d)

SUBMIT

71.

What is WTForms in Flask?

a)

A database

b)

A built-in web server

c)

A form handling library

d)

A CSS framework

72.

How do you retrieve form data in Flask?

a)

form.input()

b)

request.input()

c)

request.form

d)

get.form

73.

What is SQLAlchemy?

a)

A MySQL GUI

b)

A Flask template

c)

An ORM for Python

d)

A CSS framework

74.

What does ORM stand for?

a)

Object Related Model

b)

Object Relational Mapping

c)

Online Resource Manager

d)

Open Request Method

75.

What method is used to save an object in SQLAlchemy?

a)

insert()

b)

commit()

c)

execute()

d)

store()

76.

Which file is used to define models in a Flask app?

a)

models.html

b)

views.py

c)

models.py

d)

database.sql

77.

What is the purpose of session in Flask?

a)

To store user preferences in cookies

b)

To maintain user login state

c)

To connect to database

d)

To send emails

78.

Which method is used to protect routes in Flask apps?

a)

@form_validate

b)

@auth_only

c)

@login_required

d)

@post_only

79.

A Task Manager typically requires which of the following features?

a)

Adding and removing users

b)

Login, Add Task, Mark Complete

c)

Web scraping

d)

Payment gateway

80.

Which folder in Flask holds static CSS and JS files?

a)

public

b)

assets

c)

static

d)

styles

81.

What does HTML stand for?

a)

Hyperlink Text Markup Language

b)

Hyper Text Markup Language

c)

Home Tool Markup Language

d)

Hyper Tool Multi Language

82.

Which tag is used to create a table in HTML?

a)

b)

c)

d)

83.

Which tag is used to input text in forms?

a)

b)

c)