wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Revision module 3

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which module in Python supports regular expressions?

a)

re

b)

regex

c)

pyregex

d)

none of the mentioned

2.

Which of the following creates a pattern object?

a)

re.create(str)

b)

re.regex(str)

c)

re.compile(str)

d)

re.assemble(str)

3.

The character Dot (that is, ‘.’) in the default mode, matches any character other than _____________

a)

caret

b)

ampersand

c)

percentage symbol

d)

newline

4.

The function of re.search is:

a)

Matches a pattern at the start of the string

b)

Matches a pattern at the end of the string

c)

Matches a pattern from any part of a string

d)

Such a function does not exist

5.

The output of the two codes shown below is the same. State whether true or false.

p = re.compile('hello')

r = p.match('hello everyone')

print(r.group(0))

r = re.match('hello', 'hello everyone')

print(r.group(0))

a)

True

b)

False

c)

May be

d)

Can't say

6.

To open a file c:\scores.txt for reading, we use

a)

infile = open(“c:\scores.txt”, “r”)

b)

infile = open(“c:\\scores.txt”, “r”)

c)

infile = open(file = “c:\scores.txt”, “r”)

d)

infile = open(file = “c:\\scores.txt”, “r”)

7.

The readlines() method returns

a)

str

b)

a list of lines

c)

a list of single characters

d)

a list of integers

8.

Which of the following returns a string that represents the present working directory?

a)

os.getcwd()

b)

os.cwd()

c)

os.getpwd()

d)

os.pwd()

9.

What will be the output of the following Python code?

x=10

y=8

assert x>y, 'X too small'

a)

Assertion Error

b)

10 8

c)

No output

d)

108

10.

The module used to move ,copy,delete and rename files in Python program is

a)

Path

b)

Os

c)

shutil