After the execution of the following code, which statement would be correct?
a = 2
b = 3
c = 1
def fun(a, b)
c = a * 2 + b
return c
c = fun(a = 1, b = 2)
The line
1 is 1.0
would return?
After the lines
a = (1, 2, 3)
a = list(a)
Which of the following statements is NOT correct?
Assume variable "var" references a list. The line
var[2:]
would
What does a "byte" refer to?
After the line
a = 4.0
the variable "a" will reference to
Which of the following lines would create a list in Python?
What does the "raise" keyword do?
Putting code inside of a "try"-block will let you..
list(range(5))
The code
a = [str(i) for i in range(3)]
will
def fun(a, b):
c = fun(a=a, b=b)
Which output, if any, would be generated by the following code?
true = True
false = False
if false:
print("First output!")
elif false:
print("Second output!")
print("Third output!")
else:
print("Last output!")
a = "4"
the variable "a" will
Which of the following lines would create a comment in Python?
Python code is typically stored in...
Given a function
def add(a, b=1):
c = a +b
which of the following lines would NOT be correct?
(1, 'a', 1.0)
def add(a, b)
c = a + b
Assuming "a", "b", and "c" are referencing float objects, the line
a + b * c + b
while True:
print(“x”)
What does a "bit" refer to?
a == b
What is the advantage of using a with-as block when opening a file? Example:
with open("somefile.txt", "r") as f:
print(f.read())
What does the code snippet class Fish(Animal) do?
class Fish(Animal)
Which functionality does the module argparse provide?
my_arr1 and my_arr2 are numpy arrays with shape (3, 5). What would the line my_arr1 * my_arr2 do?
Which of the following statements is correct?
What are regular expressions (re module)?
What shape does the numpy array
my_arr = np.array([0, 1, 2, 3, 4, 5]).reshape((-1, 3)) have?
Given the following code of a 2D vector, which of the four provided implementations of the special method __eq__(self, other) is correct under the assumption that two such vectors are considered equal if their attributes are equal?
class Vector2D:
def __init__(self, v1, v2):
self.v1 = v1
self.v2 = v2
What does the special method __eq__(self, other) do?
my_arr is a numpy array with shape (5, 4, 3, 2). What would the line my_arr[0, 0] return?
my_arr is a numpy array with shape (3, 5) and datatype int. What would the line my_arr + 2 do?
Regarding Python lists and numpy arrays, which of the following statements is correct?
What does os.path.join() from the os module do?
Which of the following modules can be used to call (potentially non-Python) programs?
What is the difference between open("somefile.txt", "r") and open("somefile.txt", "rb")?
Assume the following class inheritance hierarchy (base class -> subclass): Animal -> Fish -> Shark. Further assume that there are three instances of each class: my_animal, my_fish, my_shark. Which of the boolean expressions evaluates to False?
What is the output when executing the following code?
class Animal: def __init__(self, name):
self.name = name
a1 = Animal("Gabe")
a2 = Animal("Judy")
a3 = a2
a3.name = "Anna"
print(a1.name)
print(a2.name)
print(a3.name)
class Animal:
def eat(self):
print("Animal eats")
class Fish(Animal):
pass
class Shark(Fish):
super().eat()
print("Shark eats")
for a in [Animal(), Fish(), Shark()]:
a.eat()
Assume that Animal is a class that provides a method bark(self). Assume that animal_1 is an instance of the class Animal, created via
animal_1 = Animal(). How can the method bark be invoked?
What is the difference between object/instance attributes and class attributes?
Assume that Animal is a class. What does the following code do?
animal_1 = Animal()
animal_2 = Animal()
How many elements does a numpy array with shape (2, 3, 2) hold?
What is the main purpose of the numpy module?
Last changed2 years ago