Question
Python Version 3.9.1 Questions: 1. Which of the following are methods of the file object? a) Tell b) size c) open d) read 2. Debug
Python Version 3.9.1 Questions:
1. Which of the following are methods of the file object?
a) Tell
b) size
c) open
d) read
2. Debug the following code
for I in items
print I
3. Debug the following code
if I < 3:
print I
4. What line is necessary in order to use regular expressions?
a) Use regex
b) import re
c) import sys
d) import regex
5. What does the following match?
^(ab)*$
a) fab
b) ababa
c) ab
d) blah
6. What's wrong with the following code?
f = open(file, w)
print f.read()
7. What is the effect of placing a comma at the end of a print statement?
Print this is a test,
8. What is output by the following print command?
Print %d %s %d%(32, hi, 45)
9. Consider the following interactive python example.
>>> info={}
>>> info["ok"]="Oklahoma"
>>> print info["ok"]
10. The variable info is a:
a) Tuple
b) String
c) Array
d) Dictionary
11. Which item is the key?
a) Info
b) ok
c) Oklahoma
d) print
12. Consider the code:
arr=[2,4,6,8,10]
for i in range(len(arr)):
print i * arr[i], " ",
What will be printed?
- 2 4 6 8 10
- 10 8 6 4 2
- 0 4 12 24 40
- 40 24 12 4 0
13. Consider the code:
arr=[2,4,6,8,10]
for i in range(2, 4):
print arr[i], " ",
What will be printed?
- 6 8
- 4 6
- 4 6 8
- 6 8 10
14. In Python, the value of a string cannot be modified, but a string variable can be made to refer to a different string value. Because of this property we say that strings are:
a) unchangeable
b) immodifiable
c) immutable
d) static
15. What does the following program print?
import re
p=re.compile("ab")
print p.sub("ee", "rabbit")
16. What does the following program print?
import re
p=re.compile("[to]")
print p.sub("from", "From here to Atoka.")
a) Frfromm here fromfrom Afromfromka.
b) From here from Atoka.
c) To here to Atoka.
d) From here from afromka.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started