wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

PYTHON BE PYTHONING

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

What is the correct file extension for Python files?

a)

.pyth

b)

.pt

c)

.py

d)

.python

2.

Which of the following is a valid Python variable name?

a)

2value

b)

my-value

c)

value_1

d)

class

3.

What does print(type("Hello")) output?

a)

<class 'string'>

b)

<string>

c)

<class 'str'>

d)

str

4.

Which function is used to read input from a user?

a)

input()

b)

get()

c)

read()

d)

prompt()

5.

Which tool can help with debugging Python code?

a)

debug.start()

b)

ipdb

c)

pytrace

d)

bugger

6.

Which command runs a Python test using pytest?

a)

python test.py

b)

pytest test_file.py

c)

run test.py

d)

python3 -t test.py

7.

What is the output of print(5 // 2)?

a)

2.5

b)

3

c)

2.0

d)

2

8.

Which of the following keywords is used to define a function?

a)

define

b)

function

c)

def

d)

fun

9.

What will print(x) do if x was never defined?

a)

Print nothing

b)

Throw a warning

c)

Raise a NameError

d)

Set x to None

10.

What determines the scope of a variable in Python?

a)

Its data type

b)

Its indentation

c)

Its casing

d)

Its line number

11.

What happens if you don't indent inside a function?

a)

Nothing

b)

Python ignores the code

c)

SyntaxError

d)

IndentationError

12.

Which operator is used for exponentiation?

a)

^

b)

**

c)

%

d)

^^

13.

Which statement is used for decision making in Python?

a)

switch

b)

case

c)

if

d)

check

14.

Which loop repeats as long as a condition is true?

a)

for

b)

loop

c)

repeat

d)

while

15.

Which keyword is used to define a decorator?

a)

decorate

b)

@

c)

#

d)

*

16.

Which data structure is ordered and mutable?

a)

Tuple

b)

List

c)

Set

d)

Dictionary

17.

What will [x*x for x in range(3)] return?

a)

[1, 2, 3]

b)

[0, 1, 4]

c)

[1, 4, 9]

d)

[0, 2, 6]

18.

Which keyword is used to define a generator?

a)

return

b)

yield

c)

generate

d)

pass

19.

How do you get all keys from a dictionary d?

a)

d.values()

b)

d.get_keys()

c)

d.keys()

d)

keys(d)

20.

Which of the following structures ensures unique elements?

a)

List

b)

Dictionary

c)

Set

d)

Tuple

21.

Which keyword is used to define a class?

a)

function

b)

method

c)

class

d)

defclass

22.

What is self in a method definition?

a)

A global variable

b)

The class name

c)

A reference to the instance

d)

A built-in object

23.

What does __init__ do?

a)

Runs the class logic

b)

Initializes the module

c)

Initializes the object

d)

Defines a method

24.

Which decorator turns a method into a property?

a)

@attr

b)

@prop

c)

@property

d)

@getter

25.

Which of the following is NOT a principle of OOP?

a)

Encapsulation

b)

Inheritance

c)

Compilation

d)

Polymorphism

26.

Which keyword is used to inherit from another class?

a)

inherits

b)

extends

c)

from

d)

class BaseClass:

27.

Which method refers to the superclass?

a)

super()

b)

parent()

c)

base()

d)

main()

28.

Which function creates anonymous functions?

a)

def

b)

lambda

c)

anon

d)

func

29.

How is a class attribute defined?

a)

Inside a method

b)

With @classmethod

c)

Outside any method

d)

With global

30.

Which decorator is used for class methods?

a)

@class

b)

@staticmethod

c)

@classmethod

d)

@method

31.

Which keyword is used to bring in a module?

a)

require

b)

import

c)

include

d)

fetch

32.

Which file is used by pipenv to manage dependencies?

a)

requirements.txt

b)

setup.py

c)

Pipfile

d)

env.yaml

33.

Which command installs a package using pip?

a)

pip install

b)

pip get

c)

install pip

d)

pipenv add

34.

What is a typical Python script entry point?

a)

start()

b)

def script():

c)

if __name__ == "__main__":

d)

main.run()

35.

Which relationship describes one object owning many others?

a)

One-to-one

b)

One-to-many

c)

Many-to-many

d)

Inheritance

36.

Which of the following best describes a join table?

a)

A table with indexes

b)

A table linking many-to-many objects

c)

A table with all data types

d)

A system table

37.

Which module is used for regular expressions in Python?

a)

regex

b)

regexp

c)

re

d)

express

38.

What does \d match in regex?

a)

A digit

b)

A decimal

c)

A dot

d)

A date

39.

Which command is used to create a table?

a)

ADD TABLE

b)

MAKE TABLE

c)

CREATE TABLE

d)

INSERT TABLE

40.

Which command adds data to a SQL table?

a)

INSERT INTO

b)

ADD TO

c)

UPDATE

d)

PUT INTO

41.

Which SQL data type stores text?

a)

INT

b)

VARCHAR

c)

NUMERIC

d)

FLOAT

42.

What does a foreign key do?

a)

Creates a duplicate table

b)

Links two tables

c)

Deletes rows

d)

Filters rows

43.

Which keyword joins tables in SQL?

a)

JOIN

b)

MERGE

c)

APPEND

d)

LINK

44.

What does ORM stand for?

a)

Object-Related Methods

b)

Object-Relational Mapper

c)

Object Runtime Model

d)

Object Reference Module

45.

Which decorator is used in SQLAlchemy to define a column?

a)

@column

b)

Column()

c)

@Column

d)

@field

46.

Which function adds a record in SQLAlchemy?

a)

db.add(obj)

b)

obj.insert()

c)

add.record()

d)

save(obj)

47.

What is a relationship() in SQLAlchemy?

a)

A method to delete data

b)

A function for seeding data

c)

A function that links two models

d)

A data type

48.

Which relationship allows each item to have multiple related items?

a)

One-to-one

b)

One-to-many

c)

Many-to-one

d)

Singleton

49.

What does CLI stand for?

a)

Click Language Interface

b)

Command Line Interface

c)

Code Loop Interpreter

d)

Control Logic Input

50.

Which module helps build command-line apps in Python?

a)

cli

b)

terminal

c)

click

d)

command