linkedin-skill-assessments

Python (Programming Language)

Q1. What is an abstract class?

reference

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

example

if any([True, False, False, False]) == True:
    print('Yes, there is True')
>>> 'Yes, there is True'

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

reference

Q4. What statement about static methods is true?

reference

Q5. What are attributes?

Explanation Attributes defined under the class, arguments goes under the functions. arguments usually refer as parameter, whereas attributes are the constructor of the class or an instance of a class.

Q6. What is the term to describe this code?

count, fruit, price = (2, 'apple', 3.5)

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

example

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

Q8. What is one of the most common use of Python’s sys library?

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

Q10. What is the correct syntax for defining a class called Game, if it inherits from a parent class called LogicGame?

Explanation: The parent class which is inherited is passed as an argument to the child class. Therefore, here the first option is the right answer.

Q11. What is the correct way to write a doctest?

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

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

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

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

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

Explanation - use ''' to start the doc and add output of the cell after >>>

Q12. What built-in Python data type is commonly used to represent a stack?

Q13. What would this expression return?

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

Q14. What is the purpose of the “self” keyword when defining or calling instance methods?

Simple example

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

Q15. Which of these is NOT a characteristic of namedtuples?

We need to import it using:from collections import namedtuple

Q16. What is an instance method?

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

Reference

Q18. What is the purpose of an if/else statement?

Reference

Q19. What built-in Python data type is best suited for implementing a queue?

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

Q21. What does the built-in map() function do?

Explanation: - The synax for map() function is list(map(function,iterable)). 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?

Q23. What is the purpose of the pass statement in Python?

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

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

Q26. When does a for loop stop iterating?

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?

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)]
output = []

fruit_tuple_0 = (first[0], quantities[0], price[0])
output.append(fruit_tuple)

fruit_tuple_1 = (first[1], quantities[1], price[1])
output.append(fruit_tuple)

fruit_tuple_2 = (first[2], quantities[2], price[2])
output.append(fruit_tuple)

return output
i = 0
output = []
for fruit in fruits:
    temp_qty = quantities[i]
    temp_price = prices[i]
    output.append((fruit, temp_qty, temp_price))
    i += 1
return output
groceries = zip(fruits, quantities, prices)
return groceries

>>> [
('Apples', 5, 1.50),
('Oranges', 3, 2.25),
('Bananas', 4, 0.89)
]
i = 0
output = []
for fruit in fruits:
    for qty in quantities:
        for price in prices:
            output.append((fruit, qty, price))
    i += 1
return output

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

Explanation - all() returns true if all in the list are True, see example below

test = [True,False,False,False]
if all(test) is True:
    print('Yeah all are True')
else:
    print('There is an imposter')
>>> 'There is an imposter'

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

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

Q31. What is the algorithmic paradigm of quick sort?

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

Q33. What is key difference between a set and a list?

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

Q35. 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
['a', 'b', 'c'], [1, 2, 3]
aaa
bbb
ccc
111
222
333
a 1 2 3
b 1 2 3
c 1 2 3

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

def sum(a, b):
    # a = 1
    # b = 2
    # sum(a, b) = 3

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

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

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

Explanation: Use """ to start and end the docstring and use >>> 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?

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

Example

# namedtuple function accepts the following arguments to generate a class
from collections import namedtuple
>>> Point = namedtuple('Point',['x','y'])
>>> point = Point(100, 200)
>>> point
    Point(x=100, y=200)

# Which let you use both unpacking and iteration to access
>>> x, y = point
>>> print(f'({x}, {y})')
    (100, 200)
>>> for coordinate in point:
        print(coordinate)
    100
    200

Reference

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

Q40. 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
}

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

5 != 6

Explanation - != is equivalent to not equal to in python

Q42. What does a class’s __init__() method do?

Example:

class test:
    def __init__(self):
        print('I came here without your permission lol')
        pass
t1 = test()
>>> 'I came here without your permission lol'

Q43. What is meant by the phrase “space complexity”?

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

Q45. 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}

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

Explanation: - Try running the example of the Q42 without passing self argument inside the __init__, you’ll understand the reason. You’ll get the error like this __init__() takes 0 positional arguments but 1 was given, 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?

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

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

explanation for 52 & 53

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

Q51. Describe the functionality of a deque.

Explanation - deque 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?

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

class __init__(self):
    pass
def __init__():
    pass
class __init__():
    pass
def __init__(self):
    pass

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

Q55. Why would you use a decorator?

Q56. When would you use a for loop?

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

def tax(my_float):
    '''Calculates the sales tax of a purchase. Takes in a float representing the subtotal as an argument and returns a float representing the sales tax.'''
    pass
def tx(amt):
    '''Gets the tax on an amount.'''
def sales_tax(amount):
    '''Calculates the sales tax of a purchase. Takes in a float representing the subtotal as an argument and returns a float representing the sales tax.'''
def calculate_sales_tax(subtotal):
    pass

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

explanation

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

explanation

Q60. Why would you use mixin?

explanation

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

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

Explanation Stack uses the last in first out approach

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

Q64. Why is it considered good practice to open a file from within a Python script by using the with keyword?

explanation

Q65. Why would you use a virtual environment?

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

tutorial video

Q67. What is a lambda function ?

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?

Q69. What does a generator return?

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

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

def get_next_card():
  # method body goes here
def get_next_card(self):
  # method body goes here
def self.get_next_card():
  # method body goes here
def self.get_next_card(self):
  # method body goes here

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

Q73. How is comment created?

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

my_list = ['kiwi', 'apple', 'banana']

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

Q76. Describe the functionality of a queue?

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

num_people = 5

if num_people > 10:
    print("There is a lot of people in the pool.")
elif num_people > 4:
    print("There are some people in the pool.")
else:
    print("There is no one in the pool.")
num_people = 5

if num_people > 10:
    print("There is a lot of people in the pool.")
if num_people > 4:
    print("There are some people in the pool.")
else:
    print("There is no one in the pool.")
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.")
else;
    print("There is no one in the pool.")
if num_people > 10;
    print("There is a lot of people in the pool.")
if num_people > 4;
    print("There are some people in the pool.")
else;
    print("There is no one in the pool.")

Q78. How does defaultdict work?

Q79. What is the correct syntax for adding a key called variety to the fruit_info dictionary that has a value of Red Delicious?

Q80. When would you use a while loop?

Simple Example

i = 1
while i<6:
    print('Countdown:',i)
    i = i + 1

Q81. What is the correct syntax for defining an __init__() method that sets instance-specific attributes upon creation of a new class instance?

def __init__(self, attr1, attr2):
    attr1 = attr1
    attr2 = attr2
def __init__(attr1, attr2):
    attr1 = attr1
    attr2 = attr2
def __init__(self, attr1, attr2):
    self.attr1 = attr1
    self.attr2 = attr2
def __init__(attr1, attr2):
    self.attr1 = attr1
    self.attr2 = attr2

Explanation: When instantiating a new object from a given class, the __init__() method will take both attr1 and attr2, and set its values to their corresponding object attribute, that’s why the need of using self.attr1 = attr1 instead of attr1 = attr1.

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

def count_recursive(n=1):
    if n > 3:
        return
    print(n)

    count_recursive(n + 1)
1
1
2
2
3
3
3
2
1
3
3
2
2
1
1
1
2
3

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

Q84. What will this code fragment return?

import numpy as np
np.ones([1,2,3,4,5])

Reference

Q85. You encounter a FileNotFoundException while using just the filename in the open function. What might be the easiest solution?

Q86. what will this command return?

{x for x in range(100) if x%3 == 0}

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

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

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

reference here

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

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

a = np.array([1,2,3,4])
print(a[[False, True, False, False]])

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

z = y.split(';')
len(z)

Explanation:

y="stuff;thing;junk"
	len(z) ==> 3

y="stuff;thing;junk;"
	len(z) ==> 4

Q93. What is the output of this code?

num_list = [1,2,3,4,5]
num_list.remove(2)
print(num_list)

Explanation:

num_list = [1,2,3,4,5]

num_list.pop(3)
>>> [1,2,4,5]

num_list.remove(2)
>>> [1,3,4,5]

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

[10,9,8,7,6,5,4,3,2,1]

Reference

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

import math
print(math.pow(2,10)) # prints 2 elevated to the 10th power
print(2^10)
print(2**10)
y = [x*2 for x in range(1,10)]
print(y)
y = 1
for i in range(1,10):
    y = y * 2
print(y)

Reference

Q96. Elements surrounded by [] are _, {} are _, and () are _.

Reference

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

table = np.array([
    [1,3],
    [2,4]])
print(table.max(axis=1))

Reference

Q98. What will this code print?

number = 3
print (f"The number is {number}")

Reference

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

Reference

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

  1. Reference
  2. Reference

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

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

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

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?

my_dictionary = {
    'A': 1,
    'B': 2,
    'C': 3,
    'D': 4,
    'E': 5
}
letters = []

for letter in my_dictionary.values():
    letters.append(letter)

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 print function. What function can you use within NumPy to force it to print the entire array?

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

Reference

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

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

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

x = {1,2,3,4,5}
x.add(5)
x.add(6)

Explanation: The .add() 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?

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

Q111. What is wrong with this function definition?

def be_friendly(greet = "How are you!", name):
    pass

Q112. Given that NumPy is imported as np, which choice will return True?

a = np.zeros([3,4])
b = a.copy()
np.array_equal(a,b)
a = np.empty([3,4])
b = np.empty([3,4])
np.array_equal(a,b)
a = np.zeros([3,4])
b = np.zeros([4,3])
np.array_equal(a,b)
a = np.array([1, np.nan])
np.array_equal(a,a)

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

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

import numpy as np
a = np.array([1,2,3])
b = np.array([4,5,6])
c = a*b
d = np.dot(a,b)
c = [ a[1] * b[1], a[2] * b[2], a[3] * b[3] ]
d = sum(c)
c = a[0] * b[0], a[1] * b[1], a[2] * b[2]

d = [ a[0] * b[0], a[1] * b[1], a[2] * b[2] ]
c = [ a[0] * b[0], a[1] * b[1], a[2] * b[2] ]

d = sum(a) + sum(b)
c = [ a[0] * b[0], a[1] * b[1], a[2] * b[2] ]

d = sum(c)

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

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

Reference

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

num_list = [21, 13, 19, 3, 11, 5, 18]
num_list.sort()
num_list[len(num_list) // 2]

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?

Reference

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

Reference

Q120. Which choice is an immutable data type?

Reference

Q121. What is the output of this code?

def myFunction(country = "France"):
    print("Hello, I am from", country)

myFunction("Spain")
myFunction("")
myFunction()
Hello, I am from Spain
Hello, I am from
Hello, I am from
Hello, I am from France
Hello, I am from France
Hello, I am from France
Hello, I am from Spain
Hello, I am from
Hello, I am from France
Hello, I am from Spain
Hello, I am from France
Hello, I am from France

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

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?

Q129

Explanation: The titanic['Survived'] returns a pandas.Series object, which contains the Survived column of the DataFrame. Adding the values of this column (i.e. sum(titanic['Survived'])) 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?

characters = ["Iron Man", "Spider Man", "Captain America"]
actors = ["Downey", "Holland", "Evans"]

# example output : [("IronMan", "Downey"), ("Spider Man", "Holland"), ("Captain America", "Evans")]
d = {}

for x in range(1, len(characters)):
    d[x] = actors[x]

Q125. What will this statement return?

{x : x*x for x in range(1,100)}

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?

Q132

Reference

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

Q128. What will be the output of this code?

[1,2,3] * 3

Q129. Given a list defined as numbers = [1,2,3,4], what is the value of numbers[-2]?

Q130. Which statement about strings in Python is true?

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

() -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 sin function from the math library. What is the correct syntax for importing only that function?

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

Q134. What will this code print?

print ("foo" if (256).bit_length() > 8 else "bar")

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

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

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

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 _.

Q132

Reference

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

import numpy as np

a = np.arange(100)
b = a[50:60:2]

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

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 _?

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?

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

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?

import numpy as np

def can_matrices_be_multiplied (matrix1, matrix2):
    rowsMat1, columnsMat1 = matrix1.shape
    rowsMat2, columnsMat2 = matrix2.shape

    if _____ == ______ :
        print('The matrices can be multipled!')
        return True
    else:
        return False

Q145. What is the output of this comprehension?

[(x, x+1) for x in range(1,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 __.

Reference

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

class Father():
    name = 'Robert'

class Person(Father):
    def __init__(self, name):
        self.fathername = super.name
        self.name = name

    def introduce(self):
        print("My name is", self.name, "son of", self.fathername)

king = Person("Joffrey")
king.introduce()

class Father():
    name = 'Robert'


class Person(Father):
    def __init__(self, name):
        self.fathername = self.name
        self.name = name

    def introduce(self):
        print("My name is", self.name, "son of", self.fathername)


king = Person("Joffrey")
king.introduce()

class Father():
    name = 'Robert'


class Person(Father):
    def __init__(self, name):
        self.name = name

    def introduce(self):
        print("My name is", self.name, "son of", super.name)

king = Person("Joffrey")
king.introduce()
class Father():
    name = 'Robert'

class Person(Father):
    def __init__(self, name):
        self.name = name

    def introduce(self):
        print("My name is", self.name, "son of", base.name)

king = Person("Joffrey")
king.introduce()

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.

animals = {
    'a': ['ant', 'antelope', 'armadillo'],
    'b': ['beetle', 'bear', 'bat'],
    'c': ['cat', 'cougar', 'camel']
}

animals = defaultdict(list, animals)

print(animals['b'])
print(animals['d'])
      ['beetle', 'bear', 'bat']
      []
      ['beetle', 'bear', 'bat']
      # an exception will be thrown
      ['beetle', 'bear', 'bat']
      None
      ['bat', 'bear', 'beetle']
      []

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: from collections import defaultdict

Reference

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

[x*2 for x in range(1,n)]

Reference

Q150. What does this code print in the console?

x = 18

if x > 10:
	if x > 15:
		print('A')
	else:
		print('B')
else:
	print('C')

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?

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

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

for i in range(5): pass

Q154. f-strings are also called:

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

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?

x = 5
y = 1 + (20 if x < 5 else 30)

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

Q157.The process of pickling in Python includes?

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 ?

print("codescracker".endswith("er"))

Q159. Is list mutable in python ?

Q160. What is the output of the following program ?

print(“programming”.center())

Q161. Who created the Python programming language?

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

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

x = 1j
print(x**2 == -1)

Explanation: The letter j acts as the imaginary unit in Python, therefore x**2 means j**2 which is equal to -1. The statement x**2 == -1 is evaluated as True.

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

print(0xA + 0xB + 0xC)

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.

Q165. What will this code output to the screen?

for i in range(5):
    print(i)
else:
    print("Done!")

Q166. Which comparison of lists and tuples in Python is correct?

Q167. Consider the following code snippet that uses decorators to calculate the execution time of execution_fn function:

import functools
import time

def timer(MISSING_ARG_1):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        start_time = time.perf_counter()
        rval = func(*args, **kwargs)
        end_time = time.perf_counter()
        duration = end_time - start_time
        print(f"Executed in {duration:.4f} seconds")
        return MISSING_ARG_2
    return MISSING_ARG_3

@timer
def execution_fn():
    for i in range(3):
        time.sleep(1)

execution_fn()

Which of the following choices are the missing arguments?

MISSING_ARG_1 = wrapper

MISSING_ARG_2 = rval

MISSING_ARG_3 = func
MISSING_ARG_1 = func

MISSING_ARG_2 = rval

MISSING_ARG_3 = wrapper
MISSING_ARG_1 is empty

MISSING_ARG_2 = rval

MISSING_ARG_3 = wrapper
MISSING_ARG_1 is empty

MISSING_ARG_2 = rval

MISSING_ARG_3 = func

Q168. Which of the following statements defines a new object type named “Dog” in Python?

Q169. To use pipelines in scikit-learn, import from the scikit-learn._ submodule.

Q170. You should pass in a value of _ for the axis argument to the Pandas apply method to apply the function to each row.

Q171. Data points in pyplot are called

Q172. What does this code print?

a = np.array([[1, 2], [3, 4], [5, 6]])
c = a[(a > 3) & (a < 11)]
print(c)