Linkiden Flashcards
What is an abstract class
An abstract class exists only so that other “concrete” classes can inherit from the abstract class
What happens when you use the build-in function any() on a list?
the any() function returns True if all item in the list evaluates to True. Other wise, it returns False.
what data structure does a binary tree degenerate to if it isn’t balanced properly?
Linked List
What statement about static methods is true?
Static methods server mostly as utility methods or helper methods, since they can’t access or modify a class’s state
What are attributes
Attributes are a way to hold data or describe a state for a class or instance of a class
What is the term to describe this code?
count, fruit, price = (2, 'apple', 3.5)
Tuple unpacking
What built-in list method would you use to remove items from a list?
“.pop()” method
what is one of the most common use of Python’s sys library
To capture command-line arguments given at a file’s runtime
what is the runtime of accessing a value in a dictionary by using its key?
O(1), also called constant time
What is the correct syntax for defining a class called Game
class Game: pass
what is the correct way to write a doctest
def sum(a, b):
“””
»_space;> sum(4,3)
7
>>> sum(-4,5) 1 """ return a + b
What built-in Python data type is commonly used to represent a stack
list
What would this expression return?
~~~
college_years = [‘Freshman’, ‘Sophomore’, ‘Junior’, ‘Senior’] return list(enumerate(college_years, 2019))
~~~
[(2019, ‘Freshman’), (2020, ‘Sophomore’), (2021, ‘Junior’), (2022, ‘Senior’)]
How doses defaultdict work
if you try to access a key in a dictionary that doesn’t exist, defaultdict will create a new key for you instead
What is the correct syntax for defining a class called “Game” ,if it inherits from a parent class called “LogicGame”?
class Game(LogicGame): pass
What is the purpose of the “self” keyword when defining or calling instance methods?
self refers to the instance whose method was called
Which is NOT a characteristic of Named tuples
No import is needed to use named tuples because they are available in the standard library
What is an instance Method?
Instance methods can modify the state of an instance or the state of its parent class.
Which choice is the most syntactically correct example of the conditional branching?
num_people = 5
if num_people > 10:
print(“There is a lot of people in the pool.”)
elif num_people > 4:
print(“There are some people in the pool.”)
elif num_people > 0:
print(“There are a few people in the pool.”)
else:
print(“There is no one in the pool.”)
Which statement does NOT describe the object-oriented programming concept of encapsulation?
It only allows the data to be changed by methods.
What is the purpose of an If/else statement
An if/else exectues one chunk of code if the condition is true, but a different chunk of code if the condition is false
what built-in Python data type is commonly used to represent a queue
list
What is the correct syntax for instantiating a new object of the type Game
my_game = Game()
what does the built-in map() function do?
it applies a function to each item in an iterable and returns the value of that function.
If you don’t explicitly return a value from a function, what happens?
If the return keyword is absent, the function will return None
What is the purpose of the pass statement in Python?
it is a null operation used mainly as a placeholder in functions, classes, etc
What is the term used to describe items that may be passed into a function
arguments
Which collection type is used to associate values with unique keys
dictionary