1What does input() always return?
A string
2Which operator performs floor division in Python?
3What sequence does range(2, 10, 3) produce?
2, 5, 8
4Which logical operator checks that a value is outside a range?
or
5How many times does the inner body run for an outer range(3) and an inner range(4)?
6What is a void function?
A function that runs its statements and returns no value (None)
7What happens if you use a local variable from a different function?
A NameError
8What does file mode 'w' do to existing contents?
Erases them
9Which part of try/except runs only when no exception occurs?
10What does list.sort() return?
None, because it sorts in place
11What does b = a do when a is a list?
Makes b point to the same list, not a copy
12What is [10, 20, 30, 40, 50][1:4]?
- [10, 20, 30, 40]
- [20, 30, 40]
- [20, 30, 40, 50]
- [10, 20, 30]
13Are Python strings mutable or immutable?
Immutable
14What does find() return when the substring is not found?
-1
15What does 'hello'[
-1] return?
16What does d.get('c', 0) return if 'c' is not a key?
0
17How do you create an empty set?
set(), because {} makes an empty dictionary
18How do set remove() and discard() differ when the item is missing?
remove() raises KeyError; discard() does not
19What is {1, 2, 3} ^ {3, 4}?
- {3}
- {1, 2, 3, 4}
- {1, 2, 4}
- {1, 2}
20Which file mode is used to unpickle with pickle.load?
'rb'
21What does __init__ do in a class?
Runs automatically when an object is created and initializes its attributes
22Which parameter must be the first one in every method of a class?
23What is an accessor method?
A getter that returns an attribute value without changing it
24What does class Car(Automobile) mean?
Car inherits from Automobile, an "is a" relationship
25Which SQLite type corresponds to a Python float?
26What must a primary key never be?
NULL, and it must be unique
27What does cur.fetchone() return when no rows remain?
None
28Which call saves INSERT, UPDATE and DELETE changes?
conn.commit()
29Which wildcard in a LIKE pattern matches any characters?
30What does CREATE TABLE IF NOT EXISTS prevent?
An error from recreating an existing table on every run