NEW
Font size
WorksheetsPython Functions and File Operations Quiz cyber 2025
Total questions: 18
Worksheet time: 9mins
What keyword is used to define a function in Python?
def
function
func
define
What is the term for data passed into a function?
Parameters
Arguments
Variables
Constants
What will happen if you call a function with fewer arguments than it expects?
It will use default values
It will raise an error
It will ignore the extra arguments
It will return None
What symbol is used to denote arbitrary arguments in a function definition?
*
@
**
&
What is the purpose of the return statement in a function?
To print output
To pass data back to the caller
To end the function
To define a function
Which of the following is a valid way to call a function with keyword arguments?
my_function('Emil', lname='Refsnes')
my_function('Emil', 'Refsnes', 'Tobias')
my_function('Emil', 'Refsnes')
my_function(child1='Emil', child2='Refsnes')
What does the **kwargs syntax allow in a function?
Only positional arguments
Only keyword arguments
Arbitrary keyword arguments
No arguments
What is the default mode for opening a file in Python?
append
read
binary
write
Which method is used to read an entire file at once?
get()
read()
readlines()
readline()
What will happen if you try to write to a file opened in read mode?
It will append data
It will overwrite data
It will raise an error
It will write successfully
Which method is used to close a file in Python?
end()
close()
finish()
stop()
What does the os.remove() method do?
Creates a file
Renames a file
Deletes a file
Opens a file
What is the purpose of the seek() method?
To read data
To write data
To change the cursor position
To close a file
What does the tell() method return?
The file mode
The current file position
The file size
The file name
Which of the following is NOT a valid file mode in Python?
w
r
a
xw
What does the truncate() method do?
Writes to the file
Closes the file
Reads the file
Resizes the file
What is the purpose of the global keyword?
To create a global variable
To create a local variable
To pass arguments
To delete a variable
What will happen if you try to read from a file that is not open?
It will return an empty string
It will raise an error
It will return the last read data
It will return None
