Python LinkedIn Assessment

¡Supera tus tareas y exámenes ahora con Quizwiz!

Suppose a Game class inherits from two parent classes: BoardGame and LogicGame. Which statement is true about the methods of an object instantiated from the Game class?

An instance of the Game class will inherit whatever methods the BoardGame and LogicGame classes have.

What is meant by the phrase "space complexity"?

The amount of space taken up in memory as a function of the input size

What is a static method?

They serve mostly as utility methods or helper methods since they can't access or modify a class's state.

Which collection type is used to associate values with unique keys?

dictionary

Given the following three list, how would you create a new list that matches the desired output printed below? fruits = ['apples', 'oranges', 'bananas'] quantities = [5, 3, 4] prices = [1.50, 2.25, 0.89] # Desired output [('Apples', 5, 1.50), ('Oranges', 3, 2.25), ('Bananas', 4, 0.89)]

groceries = zip(fruits, quantities, prices) return groceries

What is the correct syntax for creating a variable that is bound to a set?

myset = {0, 'apple', 3.5}

What built-in list method would you use to remove items from a list?

".pop()" method

What is the runtime of accessing a value in a dictionary by using its key?

"O(1)", also called constant time

What symbol(s) do you use to assess equality between two elements?

==

What is the correct syntax for calling an instance method on a class named Game?

>>> dice = Game() >>> dice.roll()

Which statement about the class methods is true?

A class method can modify the state of the class, but it cannot directly modify the state of an instance that inherits from that class.

Describe the functionality of a deque

A deque adds items at either or both ends, and removes items at either or both ends.

What is key difference between a set and a list?

A set is an unordered collection of unique items. A list is an ordered collection of non-unique items.

What is the definition of abstraction as applied to object-oriented Python?

Abstraction means the implementation is hidden from the user, and only the relevant data or information is shown.

What is an abstract class?

An abstract class exists only so that other "concrete" classes can inherit from the abstract class.

What is the purpose of an if/else statement?

An if/else statement executes one chunk of code if a condition it true, but a different chunk of code if the condition is false

What is a class method?

Class methods can modify the state of the class, but they can't directly modify the state of an instance that inherits from that class.

What are attributes?

Function arguments are called "attributes" in the context of class methods and instance methods.

If you don't explicitly return a value from a function, what happens?

If the return keyword is absent, the function will return None.

How does "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 of throwing a "KeyError".

What is an instance method?

Instance methods can modify the state of an instance or the state of its parent class

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.

What is the purpose of the pass statement in Python?

It is a null operation used mainly as a placeholder in functions, classes, etc.

Which statement does NOT describe the object-oriented programming concept of encapsulation?

It only allows the data to be changed by methods

Which of these is NOT a characteristic of namedtuples?

No import is needed to use namedtuples because they are available in the standard library

What is runtime complexity of the list's built-in .append() method?

O(1), also called constant time

What happens when you use the build-in function "any()" on a list?

The "any()" function returns True if any item in the list evaluates to True. Otherwise, it returns False.

What does a class's init() method do?

The __init__() method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object.

What happens when you use the built-in function all() on a list?

The all() function returns True if all items in the list evaluate to True. Otherwise, it returns False.

What does it mean for a function to have linear runtime?

The amount of time it takes the function to complete grows linearly as the input size increases.

Assuming the node is in a singly linked list, what is the runtime complexity of searching for a specific node within a singly linked list?

The runtime is O(n) because in the worst case, the node you are searching for is the last node, and every node in the linked list must be visited.

What value would be returned by this check for equality? 5!=6

True

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')]

What does this function print? def print_alpha_nums(abc_list, num_list): for char in abc_list: for num in num_list: print(char, num) return print_alpha_nums(['a', 'b', 'c'], [1, 2, 3])

a 1 a 2 a 3 b 1 b 2 b 3 c 1 c 2 c 3

What does calling namedtuple on a collection type return?

a tuple subclass with iterable named fields

What is the term used to describe items that may be passed into a function?

arguments

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 correct syntax for defining a class called Game?

class Game: pass

What is the correct syntax for defining an __init__() method that takes no parameters?

def __init__(self): pass

What is the proper way to define a function?

def get_max_num(list_of_nums): # body of function goes here explanation

Correct representation of doctest for function in Python

def sum(a, b): """ >>> a = 1 >>> b = 2 >>> sum(a, b) 3 """ return a + b

What is the correct way to write a doctest?

def sum(a, b): """ >>> sum(4, 3) 7 >>> sum(-4, 5) 1 """ return a + b

What is the algorithmic paradigm of quick sort?

divide and conquer

What is the correct syntax for creating a variable that is bound to a dictionary?

fruit_info = {'fruit': 'apple', 'count': 2, 'price': 3.5}

Review the code below. What is the correct syntax for changing the price to 1.5? fruit_info = { 'fruit': 'apple', 'count': 2, 'price': 3.5 }

fruit_info ['price'] = 1.5

What is the proper way to write a list comprehension that represents all the keys in this dictionary? fruits = {'Apples': 5, 'Oranges': 3, Bananas': 4}

fruit_names = [x for x in fruits.keys()]

According to the PEP 8 coding style guidelines, how should constant values be named in Python?

in all caps with underscores separating words -- e.g. MAX_VALUE = 255

What data structure does a binary tree degenerate to if it isn't balanced properly?

linked list

What buit-in Python data type is commonly used to represent a queue?

list

What buit-in Python data type is commonly used to represent a stack?

list

What is the correct syntax for instantiating a new object of the type Game?

my_game = Game()

What is the correct syntax for calling an instance method on a class named Game?

my_game = Game() my_game.roll_dice()

Which choice is the most syntactically correct example of 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.")

What is the purpose of the "self" keyword when defining or calling instance methods?

self refers to the instance whose method was called

What is the purpose of the self keyword when defining or calling methods on an instance of an object?

self refers to the instance whose method was called.

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 term to describe this code? count, fruit, price = (2, 'apple', 3.5)

tuple unpacking

When does a for loop stop iterating?

when it has assessed each item in the iterable it is working on or a break keyword is encountered


Conjuntos de estudio relacionados

Week 1: What are Psychological Tests?

View Set

FIN 1115 01---Personal Finance Question Set #7

View Set

EQUITY INDEXED ANNUITIES - CH 11

View Set

Chapters 18 and 19 Cardiovascular system and blood vessels, A&P II: Chapter 18 - The Heart Test Questions, CHAPTER 18- Heart Quiz+ Practice Questions, Chapter 18 Heart Multiple Choice, Chapter 19: The Cardiovascular System: Blood Vessels > Chapter Pr...

View Set

Photosynthesis - the Calvin Cycle

View Set

Unit 3 - Investment Companies Part 3

View Set