Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
56 Cards in this Set
- Front
- Back
T/F
Suppose d = {'john':40, 'peter':45}; the expression 40 in d is __________. |
False
|
|
Assume two sets exist as shown below:
set1 = set([2, 3, 4, 5, 9]) set2 = set([2, 3, 5, 8, 12, 24]) What is contained in set3 given the following statement? set3 = set1.difference(set2) | set2.difference(set1) |
set3 = (4, 8, 9, 12, 24)
|
|
T/F
The following is a valid statement assuming alist has already been declared as a list: if 5 in alist: print '5 is in the list' |
True
|
|
Suppose d = {'john':40, 'peter':45}, what happens when retieving a value using d['susan']?
|
Since 'susan' is not a key in the set, Python raises a KeyError exception.
|
|
A function _________.
|
..may have no parameters
|
|
Suppose t = (1, 2, 4, 3), t[1 : -1] is _________.
|
(2,4)
|
|
When writing a function in python, how is a void function written (i.e. a function that does not return anything?
|
By not using a return statement in the function definition
|
|
Analyze the following statement:
sum = 0 for d in range(0, 10, 0.1): sum += sum + d |
The program has a syntax error because the arguments in the range must be integers.
|
|
Suppose d = {'john':40, 'peter':45}, the keys are __________.
|
'john' and 'peter'
|
|
How many times will the following code print 'Welcome to Python'?
count = 0 while count < 10: print('Welcome to Python') count += 1 |
10
|
|
What data structure is obj in the following statement?
obj = (4, 7, 8, 3) |
Tuple
|
|
Which of the following code snippets is correct syntactically? Assume a list exists:
alist = [2, 3, 5, 78, 65] |
for elem in alist:
print elem |
|
T/F
Sets maintain order; assuming a set of numbers was created during initialization, printing the set will always result in the numbers printing in the same order as initialized. |
False
|
|
What is the number of iterations in the following loop:
for i in range(1, n): # iteration |
n-1
|
|
T/F
The function call in the following function causes syntax errors. import math def main(): math.sin(math.pi) main() Answer |
False
|
|
Tuples have what bracketing?
1, 2, 3, 4 |
(1,2,3,4)
|
|
Sets have what bracketing?
1, 2, 3, 4 |
[(1, 2, 3, 4)]
|
|
Lists have what bracketing?
|
[1, 2, 3, 4]
|
|
Dictionaries have what bracketing?
|
{1, 2, 3, 4}
|
|
Give an example of a 'floating point number'.
|
6.5
|
|
Give an example of a 'string literal'.
|
'40', str(5)
|
|
Give an example of an 'integer'.
|
14
|
|
What gets printed?
name = 'Professor McGonagall' name = name.replace('McGonagoll', 'Cat') print name |
Professor Cat
|
|
What gets printed?
result = 38 / 3.0 print result |
12.66666666
|
|
What gets printed?
result = 38 / 3 print result |
12
|
|
Given the following command line, what would argv[0], argv[1], argv[2] and argv[3] be?
% python RunMe.py file1.txt file2.txt |
argv[0] = RunMe.py
argv[1] = file1.txt argv[2] = file2.txt argv[3] = ERROR, out of bounds |
|
When using command line arguments in python, can a multiword string be sent down as one argument?
|
Yes
|
|
What gets printed, assuming 212.0 is entered in they keyboard?
fahr = raw_input('Enter the temperatures in Fahrenheit: ') celsius = 5.0 / 9.0 * (fahr - 32.0) print '%.1f' % celsius |
ERROR, fahr is not a numeric data type
|
|
What gets printed, assuming 212.0 is entered in they keyboard?
fahr =float( raw_input('Enter the temperatures in Fahrenheit: ')) celsius = 5.0 / 9.0 * (fahr - 32.0) print '%.1f' % celsius |
100.0
|
|
T/F
In python, variables must be declared and assigned a data type before using them. |
False
|
|
T/F
In python, once a variable is used, its data type may not change within a block |
False
|
|
T/F
In python, everything is an object-no primitive variables exist |
True
|
|
What numbers are printed?
for i in range (3): print i for i in range (6,9): print i |
0, 1, 2, 6, 7, 8
|
|
Which function reads in an entire data file as a list of strings, with one line per element?
|
readlines
|
|
Given the following command line, what data type would argv[1] be?
% python RunMe.py 23 4 |
A string
|
|
T/F
Indentation is not important in python |
False
|
|
T/F
A block of statements in python is delimited by the { and } brackets. |
False
|
|
What gets printed?
name = 'python' name.replace('python', 'Slytherin') print name |
python
|
|
When using the command line arguments in python, do you have to worrd about argv being null?
|
No
|
|
What gets printed?
print 'hello' 'world' |
helloworld
|
|
What gets printed?
print 'hello', 'world' |
hello world
|
|
What gets printed?
name = 'snow storm' print '%s' % name[6:8] |
to
|
|
What gets printed?
name = 'snow storm' name[5] = 'x' print name |
ERROR, this code will not run because strings are immutable and cannot be changed
|
|
What numbers get printed?
for i in range(2): print i for in in range(4,6): print i |
0, 1, 4, 5
|
|
What gets printed?
name = 'Professor McGonagall' name = name.replace('Professor McGonagall', 'the Cat' print name |
the Cat
|
|
When using command line arguments in python, must you import the sys module (or part of it) into your code?
|
Yes
|
|
What do the following function do in regards to a data file?
open |
Opens a file to be read
|
|
What do the following function do in regards to a data file?
read |
Reads a string of the file
|
|
What do the following function do in regards to a data file?
readline |
Reads one line of the file
|
|
What do the following function do in regards to a data file?
readlines |
Reads all of the file as a list of strings
|
|
What function reads an entire data file as a list of strings?
|
readlines
|
|
T/F
A statement in python must end in a semi-colon |
False
|
|
Assume two sets exist as shown below:
set 1 = set([2, 3, 6, 12, 21]) set 2 = set([2, 6, 7, 8, 12, 27]) What is contained in set3 given the following statement? set3 = set1.difference(set2) |
set3 = (3, 21)
|
|
What is the number of iterations in the following loop:
for i in range (1, 13): print i |
12
|
|
Suppose d = {'freezing':0, 'boiling':212}
They keys are _. |
freezing and boiling
|
|
T/F
The following is a valid statement assuming alist has already been declared as a list: if x in alist: print x, 'is in the list' |
True
|