Python Flashcards
Why do long integers take longer to process in Python than in most other languages?
Because they are stored internally as an array of digits.
What is the difference between double quoted strings and single quoted strings in python?
There is no difference.
Are escape characters valid in Python?
Yes.
How are invalid escape characters treated in Python?
They treated like regular text.
How can escape characters be turned off in Python?
By prefacing the string with an r (to specify a raw string).
Do multi line strings require triple single-quotes or triple double-quotes?
Either.
When does the interpreter automatically add new line characters to multi line strings?
Always, unless the line ends in a backslash.
Does prefacing a multi line string in python with ‘r’ prevent the interpreter from adding new line characters?
No.
Does python provide bounds checking for when indexing strings?
Yes.
What is the output of the following?
x = “carlisle”
print(x[2:3])
r
(since slices use inclusive/exclusive format)
What is the output of the following?
x = “car”
print(x[::-1])
rac
What is the output of the following?
x = “bugman”
print(x[2:44])
gman
(valid, despite apparent out of bounds)
What is the output of the following?
x = “bugman”
x[2] = “s”
print(x)
This issues an error, since strings are immutable in Python.
Is the following valid, where x is a list of length 4?
print(x[2:99])
Yes.
How are lists in Python implemented at the memory level?
As dynamically resized arrays of pointers.
Why aren’t lists in Python implemented as linked lists at the memory level?
Because operations on linked lists (especially indexing) is much too slow.