wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

grade 9 week 3

Total questions: 51

Worksheet time: 26hrs 30mins

Name
Class
Date
1.

What is a data type?

a)

Type of application

b)

Category for values

c)

Type of function

d)

Storage file

2.

Which of the following is NOT a built-in data type?

a)

Integer

b)

Boolean

c)

Car

d)

String

3.

What is a user-defined data type?

a)

Random function

b)

System variable

c)

Data type created by the programmer

d)

Error message

4.

In Python, how do you define a new data type?

a)

Using int

b)

Using define

c)

Using class

d)

Using object

5.

What is an object in programming?

a)

Image

b)

Function

c)

Variable that stores an instance of a class

d)

Error

6.

What is contained in a class?

a)

Only numbers

b)

Only strings

c)

Variables and functions

d)

Only files

7.

Which keyword is used to create a class in Python?

a)

type

b)

make

c)

class

d)

object

8.

What is the purpose of the __init__ function in a Python class?

a)

Delete data

b)

Initialize object properties

c)

Print data

d)

Repeat values

9.

How do you create an object from a class?

a)

Call it like a function

b)

Use a loop

c)

Print the class

d)

Import the class

10.

What is the output type of a class object?

a)

String

b)

Instance

c)

List

d)

Float

11.

What is the benefit of user-defined data types?

a)

Make the program longer

b)

Make the code more difficult

c)

Organize related data

d)

Slow down performance

12.

Which of the following is a class in this code?

a)

Student

b)

name

c)

self

d)

def

13.

How do you access class properties?

a)

object-property

b)

object->property

c)

object.property

d)

property.object

14.

What is meant by self in class methods?

a)

User

b)

Name

c)

Instance of the class

d)

Variable

15.

What is meant by encapsulation?

a)

Making code public

b)

Grouping data and methods into a single unit

c)

Sorting data

d)

Deleting old code

16.

What is an attribute in a class?

a)

Function

b)

Built-in method

c)

Variable within the class

d)

Input

17.

What is a method in a class?

a)

Comment

b)

File

c)

Function within a class

d)

Output

18.

Which keyword is used to create a method in a class?

a)

method

b)

def

c)

call

d)

class

19.

What will this code do?

a)

Error

b)

Create a variable

c)

Create a car object

d)

Print Honda

20.

What is mycar.model in the code above?

a)

Method

b)

Property

c)

Loop

d)

Function

21.

What is the correct way to define a class named Animal in Python?

a)

make Animal:

b)

new class Animal:

c)

class Animal:

d)

def Animal:

22.

Which keyword is used to define a function within a class?

a)

define

b)

func

c)

def

d)

function

23.

What is the output of this code?

a)

Lina

b)

name

c)

Student

d)

s

24.

What is meant by 'self' in class methods?

a)

Program

b)

User

c)

Instance of the class

d)

The class itself

25.

Which of the following correctly defines an attribute?

a)

self.age = 10

b)

age = 10

c)

def age = 10

d)

attr.age = 10

26.

What is instantiation in programming?

a)

Deleting a class

b)

Printing a method

c)

Creating an object from a class

d)

Importing Python

27.

What is the result of this code?

a)

Python 101

b)

Book

c)

title

d)

self.title

28.

What is the result of this code? class Book: def __init__(self, title): self.title = title mybook = Book("Python 101") print(mybook.title)

a)

Python 101

b)

Book

c)

title

d)

self.title

29.

How do you call a method from an object?

a)

object->method()

b)

object:method()

c)

object.method()

d)

method.object()

30.

Which of the following can be owned by a class?

a)

Only numbers

b)

Only text

c)

Attributes and methods

d)

Only variables

31.

What is the purpose of using classes in text-based programs?

a)

To increase file size

b)

To print text only

c)

To organize data and behavior

d)

To write loops only

32.

What does the __init__ function do?

a)

Deletes a class

b)

Initializes object data

c)

Duplicates a variable

d)

Imports a file

33.

Which of the following is the correct definition of a method in a class?

a)

method self():

b)

function method(self):

c)

def method(self):

d)

create method(self):

34.

Which keyword is used to access the current object in Python?

a)

current

b)

object

c)

this

d)

self

35.

In OOP, a class is like:

a)

Blueprint

b)

Variable

c)

Function

d)

Loop

36.

What is the result of this code? class Cat: def __init__(self, name): self.name = name c = Cat("Fluffy") print(c.name)

a)

Fluffy

b)

Cat

c)

name

d)

self

37.

Which method is automatically called when an object is created?

a)

__print__()

b)

__init__()

c)

__class__()

d)

__name__()

38.

What does the dot (.) operator do with an object?

a)

Deletes it

b)

Compares it

c)

Accesses its attributes or methods

d)

Loops through it

39.

What are the benefits of using user-defined data types?

a)

Make the code unreadable

b)

Combine related data

c)

Reduce accuracy

d)

Add random values

40.

What does this code print? class Dog: def __init__(self): self.sound = "Bark" d = Dog() print(d.sound)

a)

Bark

b)

sound

c)

Dog

d)

Error

41.

How do you define a class without properties?

a)

class Empty: None

b)

class Empty(): pass

c)

class Empty: do nothing

d)

class pass

42.

Which of the following best describes an object?

a)

A collection of code

b)

A value stored in memory

c)

An instance of a class

d)

A loop within a class

43.

Can a class method return a value?

a)

No

b)

Yes

c)

Only if printed

d)

Only with input

44.

What is the file extension for saving Python programs?

a)

.txt

b)

.exe

c)

.html

d)

.py

45.

What is the output? class Hello: def say_hi(self): return "Hi!" obj = Hello() print(obj.say_hi())

a)

Hi!

b)

say_hi

c)

Hello

d)

obj

46.

What is a method?

a)

A comment

b)

A function within a class

c)

A number

d)

A type of error

47.

How do you define multiple properties in __init__?

a)

By using return

b)

Using self multiple times

c)

Only with a comma

d)

Not allowed

48.

What is an example of object creation?

a)

Student()

b)

s = Student()

c)

def Student()

d)

print(Student)

49.

How can we use input with a user-defined type?

a)

Input is not allowed

b)

By writing inside print

c)

With input() and passing to __init__

d)

Only with strings

50.

Which function is executed first when an object is created?

a)

show()

b)

print()

c)

__init__()

d)

__call__()

51.

Apa yang dilakukan konstruktor?

a)

Mencetak nilai

b)

Membuat nama kelas

c)

Menginisialisasi nilai saat pembuatan objek

d)

Menghapus kelas