wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Basics

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which of the following code snippets is the correct one for opening the hello.txt file for writing?

a)

output_file = open("hello.txt", "r")

b)

output_file = openFile("hello.txt", "w")

c)

output_file = open("hello.txt", "w")

d)

output_file = File("hello.txt", "w")

2.

which mode is used to open a file for exclusive creation?

a)

r

b)

w

c)

x

d)

a

3.

When you open a file using a with statement, Python will ________ the file automatically after you access it.

a)

close

b)

reset

c)

delete

d)

archive

4.

Which operator can be used on a pathlib.Path object to extend the path it represents with subdirectories or filenames?

a)

\

b)

/

c)

|

d)

*

5.

What does strip() do?

a)

removes the content of the file

b)

add in meta data

c)

splits the file

d)

Removes extra data at the beginning / end of the string

6.

var = = {"apple", "banana", "cherry"}, represents:

a)

sets

b)

dictionary

c)

tuple

d)

list

7.

df.shape is used to index, Datatype and Memory information

a)

True

b)

False

8.

Which one is NOT a legal variable name?

a)

my_Var

b)

myvar

c)

my#var

d)

_myvar

9.

Tuples are mutable.

a)

True

b)

false

10.

Before data can be written to or read from a file in Python, the file must be ________ first.

a)

append

b)

open

c)

close

d)

replace