WorksheetsEnjoy _Python
Total questions: 42
Worksheet time: 21mins
What the is output of the above code?
3
7
13
14
15
Which of the following print statements will print all the names in the list on a seperate line
names = ['Ramesh', 'Rajesh', 'Roger', 'Ivan', 'Nico']
print("\n".join(names))
print(names.join("\n"))
print(names.concatenate("\n"))
print(names.append("\n"))
print(names.join("%s\n", names))
Which module in Python supports regular expressions?
regex
re
pyregex
none of the mentioned
Which of the following creates a pattern object?
re.create(str)
re.regex(str)
re.assemble(str)
re.compile(str)
What will be the output of the following Python code?
sentence = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)', sentence)
print(matched.groups())
(‘we’, ‘are’, ‘humans’)
(we, are, humans)
(‘we’, ‘humans’)
‘we are humans’
What will be the output of the above Python code?
{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
(‘horses’, ‘are’, ‘fast’)
‘horses are fast’
'are'
What will be the output of the above Python code?
{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
(‘horses’, ‘are’, ‘fast’)
‘horses are fast’
‘are’
What does the function re.search do?
matches a pattern at the start of the string
matches a pattern at any position in the string
such a function does not exist
none of the mentioned
What does the function re.match do?
none of the mentioned
such a function does not exist
matches a pattern at any position in the string
matches a pattern at the start of the string
What will be the output of the above Python code?
{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
(‘horses’, ‘are’, ‘fast’)
‘horses are fast’
‘are’
The character Dot (that is, ‘.’) in the default mode, matches any character other than _____________
caret
ampersand
percentage symbol
newline
The expression a{5} will match _____________ characters with the previous regular expression.
5 or less
exactly 5
5 or more
exactly 4
________ matches the start and end of the string.
‘^’, ‘$’
‘$’, ‘^’
‘$’, ‘?’
‘?’, ‘^’
What will be the output of the following Python code?
re.split('\W+', 'Hello, hello, hello.')
[‘Hello’, ‘hello’, ‘hello.’]
[‘Hello, ‘hello’, ‘hello’]
[‘Hello’, ‘hello’, ‘hello’, ‘.’]
[‘Hello’, ‘hello’, ‘hello’, ”]
What will be the output of the following Python function?
re.findall("hello world", "hello", 1)
[“hello”]
[ ]
hello
hello world
Which keyword allows us to load a module in Python?
Import
Load
Include
Library
What will be the output of the following code snippet?
print(2**3 + (5 + 6)**(1 + 1))
8
121
129
127
How is a code block indicated in Python?
Brackets
Indentation
Key pair
colon
What will be the output of the following code snippet?
Infinite Loop
0 3 6 9 12
0 3 6 9 12 15
0 2 3 ... 15
Which of the following types of loops are not supported in Python?
do while
while
for
None
a = [1, 2]
print(a * 3)
Error
[1,2]
[1,2,1,2]
[1,2,1,2,1,2]
All keywords in Python are in _________
Capitalized
lowercase
UPPERCASE
NONE MENTIONED
What will be the value of the following Python expression?
4 + 3 % 5
4
2
1
7
What will be the output of the following Python code?
import datetime
print(datetime.date(2016,7,24))
Error
2016-07-24
2017-7-24
24-7-2016
Which module in Python supports regular expressions?
regex
re
pyregrex
ree
What does the function re.match do?
matches a pattern at the start of the string
matches a pattern at any position in the string
such a function does not exist
none mentioned
Which of the following can be used to open a file called myText.txt in read-only mode?
infile = open("myText.txt", “w”)
infile = open("myText.txt", r)
infile = open("myText.txt", “read”)
infile = open("myText.txt")
We import this module to work with regular expressions.
re
ReEx
RegEx
Reg
The meaning of the meta character * is
One or more occurrences
Occurrences only for Numbers
Zero or more occurrences
Occurrences only for strings
Which is not a meta character
*
%
/
\
functions that belongs to regular expression module
findall
match
search
All the above
"\S" returns a
Match where the string DOES NOT contain a white space character
Match where the string CONTAINS a white space character
Match where the string DOES NOT contain any word characters
Match where the string DOES NOT contain digits
[^pqr] returns a
Match for characters p, q, r, P, Q and R only
Match for characters p, q, and r only
Match for any character contain p, q, and r
Match for any character except p, q, and r
Which returns a match for any alphabetic lower or upper case character between a and z.
[a-z]
[a-z-A-Z]
[a-z][A-Z]
[azAZ]
Which returns a match for any two-digit numbers from 00 and 55
[0-55]
[0-5][0-5]
[0-5-0-5]
[00-55]
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)
['tech'], ['tech']
['tech'][2]
[2]['tech']
['tech', 'tech']
What will be the output of the following program
re.sub('technology', 'limited', 'wipro technology')
wipro
limited
wipro limited
wipro technology
re.purge() is used to
Search for exact match
Clear the cache
Split the string
search for numbers
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)
[ 'i am a techie in, 'python technology']
['i', 'am', 'a', 'techie', 'in', 'python','technology']
['i', 'am', 'a techie in python technology']
'i', 'am', 'a', 'techie', 'in', 'python','technology'
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")
True
False
Find the output for the following python program
import re
str= " Corona virus disease"
MyVar = re.sub("\s", "-", str)
print(MyVar)
-Corona-virus-disease-
-Corona-virus-disease
Corona-virus-disease
Corona-virus-disease-
Find the output of the fallowing python program
import re
x = re.split('[a-c]', '0a3Bc6')
print(x)
['3B']
['0', '3B', '6']
['3B','6']
['0','3B']
