wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Functions and File Operations Quiz cyber 2025

Total questions: 18

Worksheet time: 9mins

Name
Class
Date
1.

What keyword is used to define a function in Python?

a)

def

b)

function

c)

func

d)

define

2.

What is the term for data passed into a function?

a)

Parameters

b)

Arguments

c)

Variables

d)

Constants

3.

What will happen if you call a function with fewer arguments than it expects?

a)

It will use default values

b)

It will raise an error

c)

It will ignore the extra arguments

d)

It will return None

4.

What symbol is used to denote arbitrary arguments in a function definition?

a)

*

b)

@

c)

**

d)

&

5.

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

a)

To print output

b)

To pass data back to the caller

c)

To end the function

d)

To define a function

6.

Which of the following is a valid way to call a function with keyword arguments?

a)

my_function('Emil', lname='Refsnes')

b)

my_function('Emil', 'Refsnes', 'Tobias')

c)

my_function('Emil', 'Refsnes')

d)

my_function(child1='Emil', child2='Refsnes')

7.

What does the **kwargs syntax allow in a function?

a)

Only positional arguments

b)

Only keyword arguments

c)

Arbitrary keyword arguments

d)

No arguments

8.

What is the default mode for opening a file in Python?

a)

append

b)

read

c)

binary

d)

write

9.

Which method is used to read an entire file at once?

a)

get()

b)

read()

c)

readlines()

d)

readline()

10.

What will happen if you try to write to a file opened in read mode?

a)

It will append data

b)

It will overwrite data

c)

It will raise an error

d)

It will write successfully

11.

Which method is used to close a file in Python?

a)

end()

b)

close()

c)

finish()

d)

stop()

12.

What does the os.remove() method do?

a)

Creates a file

b)

Renames a file

c)

Deletes a file

d)

Opens a file

13.

What is the purpose of the seek() method?

a)

To read data

b)

To write data

c)

To change the cursor position

d)

To close a file

14.

What does the tell() method return?

a)

The file mode

b)

The current file position

c)

The file size

d)

The file name

15.

Which of the following is NOT a valid file mode in Python?

a)

w

b)

r

c)

a

d)

xw

16.

What does the truncate() method do?

a)

Writes to the file

b)

Closes the file

c)

Reads the file

d)

Resizes the file

17.

What is the purpose of the global keyword?

a)

To create a global variable

b)

To create a local variable

c)

To pass arguments

d)

To delete a variable

18.

What will happen if you try to read from a file that is not open?

a)

It will return an empty string

b)

It will raise an error

c)

It will return the last read data

d)

It will return None