What is the difference between class attributes and instance attributes Linkedin?

Explanation: - The synax for

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
73 function is
my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
75. The simple area finder using map would be like this

import math
radius = [1,2,3]
area = list(map(lambda x: round(math.pi*(x**2), 2), radius))
area
>>> [3.14, 12.57, 28.27]

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

  • The function will return a RuntimeError if you don't return a value.
  • If the return keyword is absent, the function will return
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    28.
  • If the return keyword is absent, the function will return
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    77.
  • The function will enter an infinite loop because it won't know when to stop executing its code.

Q23. What is the purpose of the
my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
78 statement in Python?

  • It is used to skip the
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    79 statement of a generator and return a value of None.
  • It is a null operation used mainly as a placeholder in functions, classes, etc.
  • It is used to pass control from one statement block to another.
  • It is used to skip the rest of a
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    80 or
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    81 and return to the start of the loop.

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

  • arguments
  • paradigms
  • attributes
  • decorators

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

  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    82
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    50
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    84
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    85

Q26. When does a for loop stop iterating?

  • when it encounters an infinite loop
  • when it encounters an if/else statement that contains a break keyword
  • when it has assessed each item in the iterable it is working on or a break keyword is encountered
  • when the runtime for the loop exceeds O(n^2)

Q27. 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.
  • The runtime is O(nk), with n representing the number of nodes and k representing the amount of time it takes to access each node in memory.
  • The runtime cannot be determined unless you know how many nodes are in the singly linked list.
  • The runtime is O(1) because you can index directly to a node in a singly linked list.

Q28. 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)]

  • A

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
0

  • B

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
1

  • C

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
2

  • D

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
3

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

  • The
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    86 function returns a Boolean value that answers the question "Are all the items in this list the same?
  • The
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    86 function returns True if all the items in the list can be converted to strings. Otherwise, it returns False.
  • The
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    86 function will return all the values in the list.
  • The
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    86 function returns True if all items in the list evaluate to True. Otherwise, it returns False.

Explanation -

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
86 returns true if all in the list are True, see example below

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
4

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

(Answer format may vary. Game and roll (or dice_roll) should each be called with no parameters.)

  • A

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
5

  • B

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
6

  • C

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
7

  • D

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
8

Q31. What is the algorithmic paradigm of quick sort?

  • backtracking
  • dynamic programming
  • decrease and conquer
  • divide and conquer

Q32. What is runtime complexity of the list's built-in
my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
91 method?

  • O(1), also called constant time
  • O(log n), also called logarithmic time
  • O(n^2), also called quadratic time
  • O(n), also called linear time

Q33. What is key difference between a
my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
47 and a
my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
48?

  • A set is an ordered collection unique items. A list is an unordered collection of non-unique items.
  • Elements can be retrieved from a list but they cannot be retrieved from a set.
  • A set is an ordered collection of non-unique items. A list is an unordered collection of unique items.
  • A set is an unordered collection unique items. A list is an ordered collection of non-unique items.

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

  • Abstraction means that a different style of code can be used, since many details are already known to the program behind the scenes.
  • Abstraction means the implementation is hidden from the user, and only the relevant data or information is shown.
  • Abstraction means that the data and the functionality of a class are combined into one entity.
  • Abstraction means that a class can inherit from more than one parent class.

Q35. What does this function print?

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
9

  • A

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
0

  • B

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
1

  • C

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
2

  • D

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
3

Q36. Pick correct representation of doctest for function in Python.

  • :

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
4

  • :

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
5

  • :

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
6

  • :

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
7

Explanation: Use

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
94 to start and end the docstring and use
my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
46 to represent the output. If you write this correctly you can also run the doctest using build-in doctest module

Q37. 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?

  • When instantiating an object, the object doesn't inherit any of the parent class's methods.
  • When instantiating an object, the object will inherit the methods of whichever parent class has more methods.
  • When instantiating an object, the programmer must specify which parent class to inherit methods from.
  • An instance of the Game class will inherit whatever methods the BoardGame and LogicGame classes have.

Q38. What does calling namedtuple on a collection type return?

  • a generic object class with iterable parameter fields
  • a generic object class with non-iterable named fields
  • a tuple subclass with non-iterable parameter fields
  • a tuple subclass with iterable named fields

Example

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
8

Reference

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

  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    96
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    97
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    98
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    99

Q40. Review the code below. What is the correct syntax for changing the price to 1.5?

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
9

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    00
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    01
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    02
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    03

Q41. What value would be returned by this check for equality?

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
04

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    05
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    06
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    77
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    28

Explanation -

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
09 is equivalent to not equal to in python

Q42. What does a class's
def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
10 method do?

  • It makes classes aware of each other if more than one class is defined in a single code file.
  • It is included to preserve backwards compatibility from Python 3 to Python 2, but no longer needs to be used in Python 3.
  • It is a method that acts as a constructor and is called automatically whenever a new object is created from a class. It sets the initial state of a new object.
  • It initializes any imports you may have included at the top of your file.

Example:

def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
0

Q43. What is meant by the phrase "space complexity"?

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    11
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    12
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    13
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    14

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

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    15
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    16
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    17
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    18

Q45. What is the proper way to write a list comprehension that represents all the keys in this dictionary?

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
19

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    20
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    21
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    22
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    23

Q46. What is the purpose of the
my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
56 keyword when defining or calling methods on an instance of an object?

  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    56 refers to the class that was inherited from to create the object using
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    56.
  • There is no real purpose for the
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    56 method. It's just legacy computer science jargon that Python keeps to stay consistent with other programming languages.
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    56 means that no other arguments are required to be passed into the method.
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    56 refers to the instance whose method was called.

Explanation: - Try running the example of the Q42 without passing

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
56 argument inside the
def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
31, you'll understand the reason. You'll get the error like this
def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
32, this means that something is going inside even if haven't specified, which is instance itself.

Q47. What statement about the class methods is true?

  • A class method is a regular function that belongs to a class, but it must return None.
  • A class method can modify the state of the class, but they can't directly modify the state of an instance that inherits from that class.
  • A class method is similar to a regular function, but a class method doesn't take any arguments.
  • A class method hold all of the data for a particular class.

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

  • You did not use very many advanced computer programming concepts in your code.
  • The difficulty level your code is written at is not that high.
  • It will take your program less than half a second to run.
  • The amount of time it takes the function to complete grows linearly as the input size increases.

Q49. What is the proper way to define a function?

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    33
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    34
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    35
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    36

explanation for 52 & 53

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

  • in camel case without using underscores to separate words -- e.g.
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    37
  • in lowercase with underscores to separate words -- e.g.
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    38
  • in all caps with underscores separating words -- e.g.
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    39
  • in mixed case without using underscores to separate words -- e.g.
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    40

Q51. Describe the functionality of a deque.

  • A deque adds items to one side and remove items from the other side.
  • A deque adds items to either or both sides, but only removes items from the top.
  • A deque adds items at either or both ends, and remove items at either or both ends.
  • A deque adds items only to the top, but remove from either or both sides.

Explanation -

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
41 is used to create block chanin and in that there is first in first out approch, which means the last element to enter will be the first to leave.

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

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    42
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    43
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    44
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    45

Q53. What is the correct syntax for defining an
def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
10 method that takes no parameters?

  • :

def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
1

  • :

def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
2

  • :

def sum(a, b):
    """
    >>> sum(4, 3)
    7

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

  • :

def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
4

Q54. Which of the following is TRUE About how numeric data would be organised in a Binary Search Tree?

  • For any given node in a binary search tree, the value of the node is greater than all the values in the node's left subtree and less than the ones in its right subtree.
  • Binary Search Tree cannot be used to organize and search through numeric data, given the complication that arise with very deep trees.
  • The top node of the binary search tree would be an arbitrary number. All the nodes to the left of the top node need to be less than the top node's number, but they don't need to ordered in any particular way.
  • The smallest numeric value would go in the top most node. The next highest number would go in its left child node, the the next highest number after that would go in its right child node. This pattern would continue until all numeric values were in their own node.

Q55. Why would you use a decorator?

  • A decorator is similar to a class and should be used if you are doing functional programming instead of object oriented programming.
  • A decorator is a visual indicator to someone reading your code that a portion of your code is critical and should not be changed.
  • You use the decorator to alter the functionality of a function without having to modify the functions code.
  • An import statement is preceded by a decorator, python knows to import the most recent version of whatever package or library is being imported.

Q56. When would you use a for loop?

  • Only in some situations, as loops are used only for certain type of programming.
  • When you need to check every element in an iterable of known length.
  • When you want to minimize the use of strings in your code.
  • When you want to run code in one file for a function in another file.

Q57. What is the most self-descriptive way to define a function that calculates sales tax on a purchase?

  • :

def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
5

  • :

def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
6

  • :

def sum(a, b):
    """
    >>> sum(4, 3)
    7

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

  • :

def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
8

Q58. What would happen if you did not alter the state of the element that an algorithm is operating on recursively?

  • You do not have to alter the state of the element the algorithm is recursing on.
  • You would eventually get a KeyError when the recursive portion of the code ran out of items to recurse on.
  • You would get a RuntimeError: maximum recursion depth exceeded.
  • The function using recursion would return None.

explanation

Q59. What is the runtime complexity of searching for an item in a binary search tree?

  • The runtime for searching in a binary search tree is O(1) because each node acts as a key, similar to a dictionary.
  • The runtime for searching in a binary search tree is O(n!) because every node must be compared to every other node.
  • The runtime for searching in a binary search tree is generally O(h), where h is the height of the tree.
  • The runtime for searching in a binary search tree is O(n) because every node in the tree must be visited.

explanation

Q60. Why would you use
def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
47?

  • You use a
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    47 to force a function to accept an argument at runtime even if the argument wasn't included in the function's definition.
  • You use a
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    47 to allow a decorator to accept keyword arguments.
  • You use a
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    47 to make sure that a class's attributes and methods don't interfere with global variables and functions.
  • If you have many classes that all need to have the same functionality, you'd use a
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    47 to define that functionality.

explanation

Q61. What is the runtime complexity of adding an item to a stack and removing an item from a stack?

  • Add items to a stack in O(1) time and remove items from a stack on O(n) time.
  • Add items to a stack in O(1) time and remove items from a stack in O(1) time.
  • Add items to a stack in O(n) time and remove items from a stack on O(1) time.
  • Add items to a stack in O(n) time and remove items from a stack on O(n) time.

Q62. Which statement accurately describes how items are added to and removed from a stack?

  • a stacks adds items to one side and removes items from the other side.
  • a stacks adds items to the top and removes items from the top.
  • a stacks adds items to the top and removes items from anywhere in the stack.
  • a stacks adds items to either end and removes items from either end.

Explanation Stack uses the last in first out approach

Q63. What is a base case in a recursive function?

  • A base case is the condition that allows the algorithm to stop recursing. It is usually a problem that is small enough to solve directly.
  • The base case is summary of the overall problem that needs to be solved.
  • The base case is passed in as an argument to a function whose body makes use of recursion.
  • The base case is similar to a base class, in that it can be inherited by another object.

Q64. Why is it considered good practice to open a file from within a Python script by using the
def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
52 keyword?

  • The
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    52 keyword lets you choose which application to open the file in.
  • The
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    52 keyword acts like a
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    55 loop, and lets you access each line in the file one by one.
  • There is no benefit to using the
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    52 keyword for opening a file in Python.
  • When you open a file using the
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    52 keyword in Python, Python will make sure the file gets closed, even if an exception or error is thrown.

explanation

Q65. Why would you use a virtual environment?

  • Virtual environments create a "bubble" around your project so that any libraries or packages you install within it don't affect your entire machine.
  • Teams with remote employees use virtual environments so they can share code, do code reviews, and collaborate remotely.
  • Virtual environments were common in Python 2 because they augmented missing features in the language. Virtual environments are not necessary in Python 3 due to advancements in the language.
  • Virtual environments are tied to your GitHub or Bitbucket account, allowing you to access any of your repos virtually from any machine.

Q66. What is the correct way to run all the doctests in a given file from the command line?

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    58
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    59
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    60
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    61

tutorial video

Q67. What is a lambda function ?

  • any function that makes use of scientific or mathematical constants, often represented by Greek letters in academic writing
  • a function that get executed when decorators are used
  • any function whose definition is contained within five lines of code or fewer
  • a small, anonymous function that can take any number of arguments but has only expression to evaluate

Reference

Explanation:

The lambda notation is basically an anonymous function that can take any number of arguments with only single expression (i.e, cannot be overloaded). It has been introducted in other programming languages, such as C++ and Java. The lambda notation allows programmers to "bypass" function declaration.

Q68. What is the primary difference between lists and tuples?

  • You can access a specific element in a list by indexing to its position, but you cannot access a specific element in a tuple unless you iterate through the tuple
  • Lists are mutable, meaning you can change the data that is inside them at any time. Tuples are immutable, meaning you cannot change the data that is inside them once you have created the tuple.
  • Lists are immutable, meaning you cannot change the data that is inside them once you have created the list. Tuples are mutable, meaning you can change the data that is inside them at any time.
  • Lists can hold several data types inside them at once, but tuples can only hold the same data type if multiple elements are present.

Q69. What does a generator return?

  • None
  • An iterable object
  • A linked list data structure from a non-empty list
  • All the keys of the given dictionary

Q70. What is the difference between class attributes and instance attributes?

  • Instance attributes can be changed, but class attributes cannot be changed
  • Class attributes are shared by all instances of the class. Instance attributes may be unique to just that instance
  • There is no difference between class attributes and instance attributes
  • Class attributes belong just to the class, not to instance of that class. Instance attributes are shared among all instances of a class

Q71. What is the correct syntax of creating an instance method?

  • :

def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
9

  • :

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
0

  • :

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
1

  • :

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
2

Q72. What is the correct way to call a function?

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    62
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    63
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    64
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    65

Q73. How is comment created?

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    66
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    67
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    68
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    69

Q74. What is the correct syntax for replacing the string apple in the list with the string orange?

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
3

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    70
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    71
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    72
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    73

Q75. What will happen if you use a while loop and forget to include logic that eventually causes the while loop to stop?

  • Nothing will happen; your computer knows when to stop running the code in the while loop.
  • You will get a KeyError.
  • Your code will get stuck in an infinite loop.
  • You will get a WhileLoopError.

Q76. Describe the functionality of a queue?

  • A queue adds items to either end and removes items from either end.
  • A queue adds items to the top and removes items from the top.
  • A queue adds items to the top, and removes items from anywhere in, a list.
  • A queue adds items to the top and removes items from anywhere in the queue.

Q77. Which choice is the most syntactically correct example of the conditional branching?

  • :

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
4

  • :

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
5

  • :

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
6

  • :

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
7

Q78. How does
def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
74 work?

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    74 will automatically create a dictionary for you that has keys which are the integers 0-10.
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    74 forces a dictionary to only accept keys that are of the types specified when you created the
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    74 (such as strings or integers).
  • If you try to read from a
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    74 with a nonexistent key, a new default key-value pair will be created for you instead of throwing a
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    79.
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    74 stores a copy of a dictionary in memory that you can default to if the original gets unintentionally modified.

Q79. What is the correct syntax for adding a key called
def sum(a, b):
    """
    sum(4, 3)
    7

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

    sum(-4, 5)
    1
    """
    return a + b
82 dictionary that has a value of
def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
83?

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    84
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    85
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    86
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    87

Q80. When would you use a
my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
80 loop?

  • when you want to minimize the use of strings in your code
  • when you want to run code in one file while code in another file is also running
  • when you want some code to continue running as long as some condition is true
  • when you need to run two or more chunks of code at once within the same file

Simple Example

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
8

Q81. What is the correct syntax for defining an
def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
10 method that sets instance-specific attributes upon creation of a new class instance?

  • :

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
9

  • :

def sum(a, b):
    ###
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    ###
    return a + b
0

  • :

def sum(a, b):
    ###
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    ###
    return a + b
1

  • :

def sum(a, b):
    ###
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    ###
    return a + b
2

Explanation: When instantiating a new object from a given class, the

def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
10 method will take both
def sum(a, b):
    """
    sum(4, 3)
    7

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

    sum(-4, 5)
    1
    """
    return a + b
92, and set its values to their corresponding object attribute, that's why the need of using
def sum(a, b):
    """
    sum(4, 3)
    7

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

    sum(-4, 5)
    1
    """
    return a + b
94.

Q82. What would this recursive function print if it is called with no parameters?

def sum(a, b):
    ###
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    ###
    return a + b
3

  • :

def sum(a, b):
    ###
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    ###
    return a + b
4

  • :

def sum(a, b):
    ###
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    ###
    return a + b
5

  • :

def sum(a, b):
    ###
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    ###
    return a + b
6

  • :

def sum(a, b):
    ###
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    ###
    return a + b
7

Q83. In Python, when using sets, you use _ to calculate the intersection between two sets and _ to calculate the union.

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    95;
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    96
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    97;
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    98
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    98;
    def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    97
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    96;
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    99

Q84. What will this code fragment return?

def sum(a, b):
    ###
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    ###
    return a + b
8

  • It returns a 5x5 matric; each row will have the values 1,2,3,4,5.
  • It returns an array with the values 1,2,3,4,5
  • It returns five different square matrices filled with ones. The first is 1x1, the second 2x2, and so on to 5x5
  • It returns a 5-dimensional array of size 1x2x3x4x5 filled with 1s.

Reference

Q85. You encounter a FileNotFoundException while using just the filename in the
def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
03 function. What might be the easiest solution?

  • Make sure the file is on the system PATH
  • Create a symbolic link to allow better access to the file
  • Copy the file to the same directory as where the script is running from
  • Add the path to the file to the PYTHONPATH environment variable

Q86. what will this command return?

def sum(a, b):
    ###
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    ###
    return a + b
9

  • a set of all the multiples of 3 less then 100
  • a set of all the number from 0 to 100 multiplied by 3
  • a list of all the multiples of 3 less then 100
  • a set of all the multiples of 3 less then 100 excluding 0

Q87. What does the // operator in Python 3 allow you to do?

  • Perform integer division
  • Perform operations on exponents
  • Find the remainder of a division operation
  • Perform floating point division

Q88. What file is imported to use dates in python?

  • datetime
  • dateday
  • daytime
  • timedate

Q89. What is the correct syntax for defining a class called Game?

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    04
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    05
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    06
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    07

reference here

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

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    08
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    09
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    10
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    11

Q91. What is the output of this code? (NumPy has been imported as np.)?

college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior']
return list(enumerate(college_years, 2019))
0

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    12
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    13
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    14
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    15

Q92. Suppose you have a string variable defined as y="stuff;thing;junk;". What would be the output from this code?

college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior']
return list(enumerate(college_years, 2019))
1

  • 17
  • 4
  • 0
  • 3

Explanation:

college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior']
return list(enumerate(college_years, 2019))
2

Q93. What is the output of this code?

college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior']
return list(enumerate(college_years, 2019))
3

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    16
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    17
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    18
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    19

Explanation:

college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior']
return list(enumerate(college_years, 2019))
4

Q94. Which command will create a list from 10 down to 1? Example:

def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
20

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    21
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    22
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    23
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    24

Reference

Q95. Which fragment of code will print exactly the same output as this fragment?

college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior']
return list(enumerate(college_years, 2019))
5

  • :

college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior']
return list(enumerate(college_years, 2019))
6

  • :

college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior']
return list(enumerate(college_years, 2019))
7

  • :

college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior']
return list(enumerate(college_years, 2019))
8

  • :

college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior']
return list(enumerate(college_years, 2019))
9

Reference

Q96. Elements surrounded by
def sum(a, b):
    """
    >>> sum(4, 3)
    7

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

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

    >>> sum(-4, 5)
    1
    """
    return a + b
27 are _.

  • sets only; lists or dictionaries; tuples
  • lists; sets only; tuples
  • tuples; sets or lists; dictionaries
  • lists; dictionaries or sets; tuples

Reference

Q97. What is the output of this code? (NumPy has been imported as np.)

class my_secrets:
    def __init__(self, password):
        self.password = password
        pass
instance = my_secrets('1234')
instance.password
>>>'1234'
0

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    28
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    29
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    30
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    31

Reference

Q98. What will this code print?

class my_secrets:
    def __init__(self, password):
        self.password = password
        pass
instance = my_secrets('1234')
instance.password
>>>'1234'
1

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    32
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    33
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    34
  • It throws a TypeError because the integer must be cast to a string.

Reference

Q99. Which syntax correctly creates a variable that is bound to a tuple?

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    35
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    36
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    37
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    38

Reference

Q100. Which mode is not a valid way to access a file from within a Python script?

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    39
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    40
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    41
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    42
  1. Reference
  2. Reference

Q101. NumPy allows you to multiply two arrays without a for loop. This is an example of _.

  • vectorization
  • attributions
  • accelaration
  • functional programming

Q102. What built-in Python data type can be used as a hash table?

  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    47
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    48
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    63
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    50

Q103. Which Python function allows you to execute Linux shell commands in Python?

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    47
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    48
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    49
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    50

Q104. Suppose you have the following code snippet and want to extract a list with only the letters. Which fragment of code will _not_ achieve that goal?

class my_secrets:
    def __init__(self, password):
        self.password = password
        pass
instance = my_secrets('1234')
instance.password
>>>'1234'
2


class my_secrets:
    def __init__(self, password):
        self.password = password
        pass
instance = my_secrets('1234')
instance.password
>>>'1234'
3

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

Explanation: The first one (the correct option) returns the list of the values (the numbers). The rest of the options return a list of the keys.

Q105. When an array is large, NumPy will not print the entire array when given the built-in
def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
54 function. What function can you use within NumPy to force it to print the entire array?

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    55
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    56
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    57
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    58

Q106. When would you use a try/except block in code?

  • You use
    def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    59 blocks when you want to run some code, but need a way to execute different code if an exception is raised.
  • You use
    def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    59 blocks inside of unit tests so that the unit testes will always pass.
  • You use
    def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    59 blocks so that you can demonstrate to your code reviewers that you tried a new approach, but if the new approach is not what they were looking for, they can leave comments under the
    def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    62 keyword.
  • You use
    def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    59 blocks so that none of your functions or methods return
    my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    28.

Reference

Q107. In Python, how can the compiler identify the inner block of a for loop?

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    65
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    66
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    67
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    68

Q108. What Python mechanism is best suited for telling a user they are using a deprecated function

  • sys.stdout
  • traceback
  • warnings
  • exceptions

Q109. What will be the value of x after running this code?

class my_secrets:
    def __init__(self, password):
        self.password = password
        pass
instance = my_secrets('1234')
instance.password
>>>'1234'
4

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    69
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    70
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    71
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    72

Explanation: The

def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
73 method adds the element to the set only if it doesn't exist.

Q110. How would you access and store all of the keys in this dictionary at once?

class my_secrets:
    def __init__(self, password):
        self.password = password
        pass
instance = my_secrets('1234')
instance.password
>>>'1234'
5

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    74
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    75
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    76
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    77

Q111. What is wrong with this function definition?

class my_secrets:
    def __init__(self, password):
        self.password = password
        pass
instance = my_secrets('1234')
instance.password
>>>'1234'
6

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    78 is a reserved word.
  • Underscores are not allowed in function names.
  • A non-default argument follows a default argument.
  • There is nothing wrong with this function definition.

Q112. Given that NumPy is imported as
def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
79, which choice will return
my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
77?

  • :

class my_secrets:
    def __init__(self, password):
        self.password = password
        pass
instance = my_secrets('1234')
instance.password
>>>'1234'
7

  • :

class my_secrets:
    def __init__(self, password):
        self.password = password
        pass
instance = my_secrets('1234')
instance.password
>>>'1234'
8

  • :

class my_secrets:
    def __init__(self, password):
        self.password = password
        pass
instance = my_secrets('1234')
instance.password
>>>'1234'
9

  • :

import math
radius = [1,2,3]
area = list(map(lambda x: round(math.pi*(x**2), 2), radius))
area
>>> [3.14, 12.57, 28.27]
0

Q113. How do you add a comment to existing Python script?

  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    69
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    67
  • def sum(a, b):
        """
        sum(4, 3)
        7
    
        sum(-4, 5)
        1
        """
        return a + b
    66
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    84

Q114. In this code fragment, what will the values of c and d be equivalent to?

import math
radius = [1,2,3]
area = list(map(lambda x: round(math.pi*(x**2), 2), radius))
area
>>> [3.14, 12.57, 28.27]
1

  • A

import math
radius = [1,2,3]
area = list(map(lambda x: round(math.pi*(x**2), 2), radius))
area
>>> [3.14, 12.57, 28.27]
2

  • B

import math
radius = [1,2,3]
area = list(map(lambda x: round(math.pi*(x**2), 2), radius))
area
>>> [3.14, 12.57, 28.27]
3

  • C

import math
radius = [1,2,3]
area = list(map(lambda x: round(math.pi*(x**2), 2), radius))
area
>>> [3.14, 12.57, 28.27]
4

  • D

import math
radius = [1,2,3]
area = list(map(lambda x: round(math.pi*(x**2), 2), radius))
area
>>> [3.14, 12.57, 28.27]
5

Q115. What two functions within the NumPy library could you use to solve a system of linear equations?

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    85
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    86
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    87
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    88

Q116. What is the correct syntax for creating a variable that is bound to a list?

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    89
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    90
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    91
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    92

Reference

Q117. This code provides the _ of the list of numbers.

import math
radius = [1,2,3]
area = list(map(lambda x: round(math.pi*(x**2), 2), radius))
area
>>> [3.14, 12.57, 28.27]
6

  • mode
  • average
  • mean
  • median

Explanation: The median is the value separating the higher half from the lower half of a data sample. Here it is 13.

Q118. What are the two main data structures in the Pandas library?

  • Arrays and DataFrames
  • Series and Matrixes
  • Matrixes and DataFrames
  • Series and DataFrames

Reference

Q119. Suppose you have a variable named
def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
93 of type np.array with 10,000 elements. How can you turn
def sum(a, b):
    """
    >>> sum(4, 3)
    7

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

    >>> sum(-4, 5)
    1
    """
    return a + b
95 with dimensions 100x100?

  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    96
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    97
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    98
  • def sum(a, b):
        """
        >>> sum(4, 3)
        7
    
        >>> sum(-4, 5)
        1
        """
        return a + b
    99

Reference

Q120. Which choice is an immutable data type?

  • dictionnary
  • list
  • set
  • string

Reference

Q121. What is the output of this code?

import math
radius = [1,2,3]
area = list(map(lambda x: round(math.pi*(x**2), 2), radius))
area
>>> [3.14, 12.57, 28.27]
7

  • :

import math
radius = [1,2,3]
area = list(map(lambda x: round(math.pi*(x**2), 2), radius))
area
>>> [3.14, 12.57, 28.27]
8

  • :

import math
radius = [1,2,3]
area = list(map(lambda x: round(math.pi*(x**2), 2), radius))
area
>>> [3.14, 12.57, 28.27]
9

  • :

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

  • :

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

Q122. Choose the option below for which instance of the class cannot be created

  • Anonymous Class
  • Parent Class
  • Nested Class
  • Abstract Class

Reference

Q123. Using Pandas, we load a data set from Kaggle, as structured in the image below. Which command will return the total number of survivors?

What is the difference between class attributes and instance attributes Linkedin?

  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    00
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    01
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    02
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    03

Explanation: The

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

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

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
05 object, which contains the
def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
06 column of the
def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
07. Adding the values of this column (i.e.
def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
00) returns the total number of survivors since a survivor is represented by a 1 and a loss by 0.

Q124. How would you create a list of tuples matching these lists of characters and actors?

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

  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    09
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    10
  • [ ]

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

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

Q125. What will this statement return?

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

  • a dictionary with x as a key, and x squared as its value; from 1 to 100
  • a dictionary with x as a key, and x squared as its value; from 1 to 99
  • a set of tuples, consisting of (x, x squared); from 1 to 99
  • a list with all numbers squared from 1 to 99

Q126. Jaccard Similarity is a formula that tells you how similar two sets are. It is defined as the cardinality of the intersection divided by the cardinality of the union. Which choice is an accurate implementation in Python?

What is the difference between class attributes and instance attributes Linkedin?

  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    12
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    13
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    14
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    15

Reference

Q127. Which choice is not a native numerical type in Python?

  • Long
  • Int
  • Float
  • Double

Q128. What will be the output of this code?

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

  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    16
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    17
  • You will get a type error.
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    18

Q129. Given a list defined as numbers =
def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
19, what is the value of
def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
20?

  • 1
  • 3
  • 2
  • An IndexError exception is thrown.

Q130. Which statement about strings in Python is true?

  • Strings can be enclosed by double quotes (") or single quotes (').
  • Strings can only be enclosed in single quotes (').
  • Single character strings must be enclosed in single quotes ('), and the rest must be enclosed in double quotes (").
  • Strings can only be enclosed in double quotes (").

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

  • definit(self): pass
  • classinit(self): pass
  • classinit(): pass
  • definit(): pass

() -empty parameter self -refers to all instances within a class init -a reserved method, aka a constructor init() -always executed when the class is being initiated

Q132. Suppose you need to use the
def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
21 function from the
def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
22 library. What is the correct syntax for importing only that function?

  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    23
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    24
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    25
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    26

Q133. What do you get if you apply numpy.sum() to a list that contains only Boolean values?

  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    27
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    28
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    29
  • my_list = [1,2,3]
    my_list.pop(0)
    my_list
    >>>[2,3]
    28

Q134. What will this code print?

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

  • True
  • foo
  • You will get an error message because constant integer values are not classes.
  • bar

Q135. If you do not explicitly return a value from a function, what happens?

  • If the return keyword is absent, the function will return True.
  • The function will enter an infinite loop because it will not know when to stop executing its code.
  • The function will return a RuntimeError if you do not return a value.
  • If the return keyword is absent the function will return None.

Q136. it is often the case that the pandas library is used for _ data and NumPy for _ data.

  • string; numerical
  • unstructured; structured
  • numerical; tabular
  • tabular; numerical

Reference

Q137. What do you need to do to install additional packages into Python?

  • Use a C compiler like gcc or clang.
  • Use a package manager like pip or conda.
  • Use an IDE like Notepad++ or Idle.
  • Use a package manager like NPM or NuGet.

Q138. The image below was created using Matplotlib. It is a distribution plot of a list of integers filled with numbers using the function _ and plotted with _.

What is the difference between class attributes and instance attributes Linkedin?

  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    31
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    32
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    33
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    34

Reference

Q139. In this code fragment, what will be the values of a and b ?

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

  • a: all integers from 0 to 99 (inclusive) b: all even integers from 50 to 58 (inclusive)
  • a: all integers from 0 to 100 (inclusive) b: all even integers from 50 to 60 (inclusive)
  • a: all integers from 0 to 99 (inclusive) b: all even integers from 50 to 60 (inclusive)
  • a: all integers from 0 to 99 (inclusive) b: all odd integers from 49 to 59 (inclusive)

Q140. When using NumPy in Python, how do you check the dimensionality (number and length of dimensions) of an object called my_object?

  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    35
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    36
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    37
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    38

Q141. Assume you have a non-empty list named mylist and you want to search for a specific value. The minimum number of comparison will be __ and the maximum number of comparison will be _?

  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    39
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    40
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    41
  • def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    42

Explanation: Can use a break statement and the value being searched can be the first element of the list, given that it is non-empty.

Q142. If a function does not have a return statement, what does it really return?

  • 0
  • True
  • None
  • False

Q143. What is a common use of python's sys library?

  • to capture command-line arguments given at a file's runtime
  • to take a snapshot of all the packages and libraries in your virtual environment
  • to connect various systems, such as connecting a web front end, an API service, a database, and a mobile app
  • to scan the health of your Python ecosystem while inside a virtual environment

Reference

Q144. Suppose you want to double-check if two matrices can be multipled using NumPy for debugging purposes. How would you complete this code fragment by filling in the blanks with the appropiate variables?

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

  • columnsMat1; rowsMat1;
  • columnsMat1; rowsMat2;
  • columnsMat1; columnsMat2;
  • columnsMat2; rowsMat1;

Q145. What is the output of this comprehension?

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
43

  • [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
  • [1,2,3,4,5]
  • [(1, 2), (2, 3), (3, 4)]
  • [(1, 2), (2, 3), (3, 4), (4, 5)]

Q146. In Python, a class method must have __ as a function decorator, and the first parameter of the method will be a reference to __.

  • @classmethod; the class
  • inline; the class
  • static; self
  • @static; self

Reference

Q147. Which snippet of code will print My name is Joffrey, son of Robert?

  • :

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

  • :

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
00

  • :

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
01

  • :

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
02

Explanation: In the first, super does not have .name (should be self.name), The third drops Robert, and base is not defined in the 4th.

Q148.

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
03

  • A

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
04

  • B

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
05

  • C

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
06

  • D

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
07

Explanation: Dictionaries usually result in an exception when using the square bracket syntax. Defaultdict here returns a default value dedicated by the first parameter so instead of throwing an exception, they return the default. Note that this needs to be imported as follows:

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
44

Reference

Q149. What will this line of code return? (Assume n is already defined as any positive integer value.)

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
08

  • a list with all the even numbers less than 2*n
  • a dictionary with all the even numbers less than 2*n
  • a list with all the odd numbers less than 2*n
  • a list with all the even numbers less than or equal to 2*n

Reference

Q150. What does this code print in the console?

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
09

  • C
  • A B
  • B
  • A

Q151. Suppose you have a variable named vector of type np.array with 10.000 elements. How can you turn vector into a variable named matrix with dimensions 100x100?

  • matrix = matrix(vector,100,100)
  • matrix = vector.to_matrix(100,100)
  • matrix = (vector.shape = (100,100))
  • matrix = vector.reshape(100,100) Exa

Q152. What is the maximum length of a Python identifier?

  • 32
  • 16
  • 128
  • No fixed length is specified

Q153. What will the value of the i variable be when the following loop finishes its execution?

for i in range(5): pass

  • 5
  • the variable becomes unavailable
  • 6
  • 4

Q154. f-strings are also called:

  • Formatted string expressions
  • Functional strings
  • Modulo formatted strings
  • Formatted string literals

Q155. How many CPUs (or cores) will the Python threading library take advantage of simultaneously?

  • One
  • All of the available CPUs
  • Two
  • Three

Explanation: Python threading is restricted to a single CPU at one time. The multiprocessing library will allow you to run code on different processors.

Q156 What will be the value of y in this code?

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
10

  • False
  • 21
  • 2
  • 31

Explanation: If x < 5 ==> y = 1 + 20 Else y = 1 + 30

Q157.The process of pickling in Python includes?

  • conversion of a Python object hierarchy into byte stream
  • conversion of a datatable into a list
  • conversion of a byte stream into Python object hierarchy
  • conversion of a list into a datatable

Explanation: Pickling is the process of sterilizing a Python object, that is, conversion of a byte stream into Python object hierarchy. The reverse of this process is known as unpickling.

Q158. What is the output of the following program ?

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
11

  • True
  • 1
  • 2
  • False

Q159. Is list mutable in python ?

  • True
  • False

Q160. What is the output of the following program ?

print("programming".center())

  • cr
  • programming
  • Error says TypeError: center expected at least 1 argument, got 0
  • None of the Above

Q161. Who created the Python programming language?

  • Tim Berners-Lee
  • Ada Lovelace
  • Guido van Rossum
  • Alan Turing

Q162. Which collection is ordered, changeable, and allows duplicate members?

  • SET
  • TUPLE
  • DICTIONARY
  • LIST

Q163. What will be printed in the console if you run this code?

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
12

  • a run-time error telling you that the variable
    def sum(a, b):
        """
        # >>> sum(4, 3)
        # 7
    
        # >>> sum(-4, 5)
        # 1
        """
        return a + b
    45 has not been initialized
  • True
  • 1j
  • False

Explanation: The letter

def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
45 acts as the imaginary unit in Python, therefore
def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

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

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
48 which is equal to
def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
49. The statement
def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
50 is evaluated as
my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
77.

Q164. What will be printed in the console if you run this code?

my_list = [1,2,3]
my_list.pop(0)
my_list
>>>[2,3]
13

  • 33
  • 63
  • 0xA + 0xB + 0xC
  • None

Explanation: A, B and C are hexadecimal integers with values 10, 11 and 12 respectively, so the sum of A, B and C is 33.

What is difference between class attributes and instance attributes?

Differences Between Class and Instance Attributes The difference is that class attributes are shared by all instances. When you change the value of a class attribute, it will affect all instances that share the same exact value. The attribute of an instance on the other hand is unique to that instance.

What is the difference between an attribute and an instance?

We make a distinction between instance attributes and class attributes. Instance Attributes are unique to each object, (an instance is another name for an object).

What is a class attribute?

Definition and Usage The class attribute specifies one or more classnames for an element. The class attribute is mostly used to point to a class in a style sheet. However, it can also be used by a JavaScript (via the HTML DOM) to make changes to HTML elements with a specified class.

Is self an instance attribute?

self represents the instance of the class. By using the “self” we can access the attributes and methods of the class in python. It binds the attributes with the given arguments. The reason you need to use self. is because Python does not use the @ syntax to refer to instance attributes.