Quiz Catalog

Catalog of quizzes

a = [[] * 2] * 2
a[0].append(1)

print(a)
[[1], [1]]
  • object/reference
  • list/operation/append
  • list/operation/multiply,

a = [[0]*2]*2
a[0][0] = 5

print(a)
[[5, 0], [5, 0]]
  • object/reference
  • list/operation/multiply

a = [2, 4, 3]
b = sorted(a)
b.insert(0, 1)

print(a[0])
2
  • object/reference

a = 4
b = a
del a
a = 2

print(b == 2)
False
  • object/reference

class Point:
  def __init__(self, name, x, y):
    self.name = name
    self.x = x
    self.y = y

  def __str__(self):
    return '{}({}, {})'.format(self.name, self.x, self.y)

points = [Point('A', 0, 3), Point('B', 4, 0)]
print(points[0])
A(0, 3)
  • object/reference

import copy

list1 = [1, 2, 3, [1, 5], ]
list2 = copy.copy(list1)
list2[3][0] = 2
print(list1, list2)
[1, 2, 3, [2, 5]] [1, 2, 3, [2, 5]]
  • object/reference
  • list/literal

class NumOperations():
def __init__(self, math_list):
  self.math_list = math_list

def __mul__(self, other):
  mullst = [x * y for x, y in zip(self.math_list, other.math_list)]
  return NumOperations(mullst)

q = NumOperations([1, 1, 0]) * NumOperations([10, 9, 8])
print('Multiplication: ' , q.math_list)
[10, 9, 0]
  • object/reference
  • list/operation/multiply

L = [[[[5, 6], [3, 4]], [1, 2]],[8, 8]]
print(L[0][1:], L[0][0][-1][1])
[[1, 2]] 4
  • object/reference

L = [[1, 2, [3, 4]], [[3, 4, 5], [1, 2]]]
print(L[0] is L[1])
False
  • object/reference
  • object/identify