Exam Revision] Flashcards
(28 cards)
What is a Hash function?
A function that maps a key to a value.
An example of this is a dictionary
True or false?
The keys of dictionaries must be immutable
True
True or false?
A valid dictionary key is (1, 2, 3)
True because tuples are immutable
Note that lists are not immutable
In the ordering of string characters, do capital letters or lowercase letters come first?
Capital letters come first.
Meaning "A" < "a"
is true
What does len(“hello world”) return?
11
Note it does not start from 0
Is string splicing right exlusive or left exclusive?
Right exlcusive
A.
D. 6 This is because the x == a
is seperate from the rest (or "c" or "e" or "g"
). And so at x = a, the first condition is fufilled (if x == a:
), and for the rest of the letters, it will basically run if "c":
which is always true and so the if statement will run for all letters
C.
You can add lists
A
What is the difference between extend and append?
extend adds multiple elements of an iterable element (concerting them to singular elements).
append adds only one element.
C.
D. Error You cannot change individual characters in a string
C. NameError
C. None “*IN PLACE*” means it replaces the list, not creating a new one so using it actually returns nothing
B. ValueError
Because it is the correct type, being a string but not correct value
D. <class ‘NoneType’>
For the instantiations at line 35-38, define each f and g functions as mathmatical representations. Like a.f(x)= 2x+5
or a.g(x)= 3x-7
A. 5.
Each \t
counts as 1 character
D. 3
Note and
takes precedence over or
A. 0
C. []
D. None of the above
It will print 6
foo always raises an error. Dictionaries cannot have mutable keys (lists)