My Report

Python Programming Practice Test 9


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which of the following statements are true?

2. Which of the following functions returns a dictionary mapping group names to group numbers?

3. Which of the following will result in an error?

4. What is the difference between r+ and w+ modes?

5. What will be the output of the following Python code?

sentence = 'horses are fast'
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, sentence)
print(matched.group(2))

6. What is the correct syntax of open() function?

7. What will be the output of the following Python code?

fo = open("foo.txt", "rw+")
print "Name of the file: ", fo.name

# Assuming file has following 5 lines
# This is 1st line
# This is 2nd line
# This is 3rd line
# This is 4th line
# This is 5th line

for index in range(5):
   line = fo.next()
   print "Line No %d - %s" % (index, line)

# Close opened file
fo.close()

8. To read two characters from a file object infile, we use ____________

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

10. What will be the output of the following Python code?

re.match('sp(.*)am', 'spam')

 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.