Python From Beginner to Advanced

0% completed

Previous
Next
Quiz
What is file handling in Python?
A
A method to manage Python software packages.
B
The process of interacting with files on the computer, including reading and writing data.
C
A technique to handle errors and exceptions in Python scripts.
D
A framework in Python for creating web applications.
How do you open a file for writing in Python?
A
open('myfile.txt', 'w')
B
open('myfile.txt', 'r')
C
open('myfile.txt', 'a')
D
open('myfile.txt', 'rb')
What does the following code do?
with open('data.txt', 'w') as f:
    f.write("Hello, world!")
A
Reads "Hello, world!" from 'data.txt'.
B
Writes "Hello, world!" to 'data.txt', replacing any existing content.
C
Appends "Hello, world!" to 'data.txt' without erasing current contents.
D
Causes a syntax error.
Which module would you use to rename a file in Python?
A
os
B
sys
C
json
D
re
How do you delete a file in Python?
A
os.remove('data.txt')
B
file.delete('data.txt')
C
os.delete('data.txt')
D
delete('data.txt')
What does the file.seek() method do in Python?
A
Deletes the specified content from a file.
B
Closes the file automatically after reading.
C
Renames the file.
D
Moves the file cursor to a specified position within the file.
Which method is used to read a single line from a file in Python?
A
read()
B
readline()
C
readlines()
D
readfile()
How do you list all files and directories within a specified directory?
A
os.listdir()
B
os.walk()
C
os.files()
D
os.view()

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next