wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Enjoy _Python

Total questions: 42

Worksheet time: 21mins

Name
Class
Date
1.

What the is output of the above code?

a)

3

b)

7

c)

13

d)

14

e)

15

2.

Which of the following print statements will print all the names in the list on a seperate line

names = ['Ramesh', 'Rajesh', 'Roger', 'Ivan', 'Nico']

a)

print("\n".join(names))

b)

print(names.join("\n"))

c)

print(names.concatenate("\n"))

d)

print(names.append("\n"))

e)

print(names.join("%s\n", names))

3.

Which module in Python supports regular expressions?

a)

regex

b)

re

c)

pyregex

d)

none of the mentioned

4.

Which of the following creates a pattern object?

a)

re.create(str)

b)

re.regex(str)

c)

re.assemble(str)

d)

re.compile(str)

5.

What will be the output of the following Python code?

sentence = 'we are humans'

matched = re.match(r'(.*) (.*?) (.*)', sentence)

print(matched.groups())

a)

(‘we’, ‘are’, ‘humans’)

b)

(we, are, humans)

c)

(‘we’, ‘humans’)

d)

‘we are humans’

6.

What will be the output of the above Python code?

a)

{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}

b)

(‘horses’, ‘are’, ‘fast’)

c)

‘horses are fast’

d)

'are'

7.

What will be the output of the above Python code?

a)

{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}

b)

(‘horses’, ‘are’, ‘fast’)

c)

‘horses are fast’

d)

‘are’

8.

What does the function re.search do?

a)

matches a pattern at the start of the string

b)

matches a pattern at any position in the string

c)

such a function does not exist

d)

none of the mentioned

9.

What does the function re.match do?

a)

none of the mentioned

b)

such a function does not exist

c)

matches a pattern at any position in the string

d)

matches a pattern at the start of the string

10.

What will be the output of the above Python code?

a)

{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}

b)

(‘horses’, ‘are’, ‘fast’)

c)

‘horses are fast’

d)

‘are’

11.

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

a)

caret

b)

ampersand

c)

percentage symbol

d)

newline

12.

The expression a{5} will match _____________ characters with the previous regular expression.

a)

5 or less

b)

exactly 5

c)

5 or more

d)

exactly 4

13.

________ matches the start and end of the string.

a)

‘^’, ‘$’

b)

‘$’, ‘^’

c)

‘$’, ‘?’

d)

‘?’, ‘^’

14.

What will be the output of the following Python code?

re.split('\W+', 'Hello, hello, hello.')

a)

[‘Hello’, ‘hello’, ‘hello.’]

b)

[‘Hello, ‘hello’, ‘hello’]

c)

[‘Hello’, ‘hello’, ‘hello’, ‘.’]

d)

[‘Hello’, ‘hello’, ‘hello’, ”]

15.

What will be the output of the following Python function?

re.findall("hello world", "hello", 1)

a)

[“hello”]

b)

[ ]

c)

hello

d)

hello world

16.

Which keyword allows us to load a module in Python?

a)

Import

b)

Load

c)

Include

d)

Library

17.

What will be the output of the following code snippet?

print(2**3 + (5 + 6)**(1 + 1))

a)

8

b)

121

c)

129

d)

127

18.

How is a code block indicated in Python?

a)

Brackets

b)

Indentation

c)

Key pair

d)

colon

19.

What will be the output of the following code snippet?

a)

Infinite Loop

b)

0 3 6 9 12

c)

0 3 6 9 12 15

d)

0 2 3 ... 15

20.

Which of the following types of loops are not supported in Python?

a)

do while

b)

while

c)

for

d)

None

21.

a = [1, 2]

print(a * 3)

a)

Error

b)

[1,2]

c)

[1,2,1,2]

d)

[1,2,1,2,1,2]

22.

All keywords in Python are in _________

a)

Capitalized

b)

lowercase

c)

UPPERCASE

d)

NONE MENTIONED

23.

What will be the value of the following Python expression?

4 + 3 % 5

a)

4

b)

2

c)

1

d)

7

24.

What will be the output of the following Python code?

import datetime

print(datetime.date(2016,7,24))

a)

Error

b)

2016-07-24

c)

2017-7-24

d)

24-7-2016

25.

Which module in Python supports regular expressions?

a)

regex

b)

re

c)

pyregrex

d)

ree

26.

What does the function re.match do?

a)

matches a pattern at the start of the string

b)

matches a pattern at any position in the string

c)

such a function does not exist

d)

none mentioned

27.

Which of the following can be used to open a file called myText.txt in read-only mode?

a)

infile = open("myText.txt", “w”)

b)

infile = open("myText.txt", r)

c)

infile = open("myText.txt", “read”)

d)

infile = open("myText.txt")

28.

We import this module to work with regular expressions.

a)

re

b)

ReEx

c)

RegEx

d)

Reg

29.

The meaning of the meta character * is

a)

One or more occurrences

b)

Occurrences only for Numbers

c)

Zero or more occurrences

d)

Occurrences only for strings

30.

Which is not a meta character

a)

*

b)

%

c)

/

d)

\

31.

functions that belongs to regular expression module

a)

findall

b)

match

c)

search

d)

All the above

32.

"\S" returns a

a)

Match where the string DOES NOT contain a white space character

b)

Match where the string CONTAINS a white space character

c)

Match where the string DOES NOT contain any word characters

d)

Match where the string DOES NOT contain digits

33.

[^pqr] returns a

a)

Match for characters p, q, r, P, Q and R only

b)

Match for characters p, q, and r only

c)

Match for any character contain p, q, and r

d)

Match for any character except p, q, and r

34.

Which returns a match for any alphabetic lower or upper case character between a and z.

a)

[a-z]

b)

[a-z-A-Z]

c)

[a-z][A-Z]

d)

[azAZ]

35.

Which returns a match for any two-digit numbers from 00 and 55

a)

[0-55]

b)

[0-5][0-5]

c)

[0-5-0-5]

d)

[00-55]

36.

What is the output of the below python program

import re

str = "now a days techies are available in different technologies"

Myvar = re.findall("tech", str)

print(Myvar)

a)

['tech'], ['tech']

b)

['tech'][2]

c)

[2]['tech']

d)

['tech', 'tech']

37.

What will be the output of the following program


re.sub('technology', 'limited', 'wipro technology')

a)

wipro

b)

limited

c)

wipro limited

d)

wipro technology

38.

re.purge() is used to

a)

Search for exact match

b)

Clear the cache

c)

Split the string

d)

search for numbers

39.

Find the output for the following python program.

imort re

str = "i am a techie in python technology"

x = re.split("\s", txt, 3)

print(x)

a)

[ 'i am a techie in, 'python technology']

b)

['i', 'am', 'a', 'techie', 'in', 'python','technology']

c)

['i', 'am', 'a techie in python technology']

d)

'i', 'am', 'a', 'techie', 'in', 'python','technology'

40.

Find the output of the below python program.

import re

str = "technpogy is the world"

MyVar = re.findall("^tech", str)

if MyVar:

print("True")

else:

print("False")

a)

True

b)

False

41.

Find the output for the following python program


import re

str= " Corona virus disease"

MyVar = re.sub("\s", "-", str)

print(MyVar)

a)

-Corona-virus-disease-

b)

-Corona-virus-disease

c)

Corona-virus-disease

d)

Corona-virus-disease-

42.

Find the output of the fallowing python program

import re

x = re.split('[a-c]', '0a3Bc6')

print(x)

a)

['3B']

b)

['0', '3B', '6']

c)

['3B','6']

d)

['0','3B']