That's a method?
Alley - OOP
Algo
Inheritance
Wild Card
100

Which option would be the best implementation of the __repr__ method?

__repr__

a. ObjName(arg1, arg2)

b. f"The Obj {self.name} contains {arg1} {arg2}"

c. 0x310788FF

a. ObjName(arg1, arg2) 

You want to provide the object type when representing using repr, readability for sake of printing is not necessary.

100
A programming paradigm that allows you to package together data states and functionality to modify those data states, while keeping the details under the hood. As a result, your code is more flexible, modular, and abstract.

What is Object Oriented Programming?

100

How would you print the current date and time in Python?

from datetime import datetime

print(datetime.now())

100

Calling the previously built methods with this function saves you from needing to rewrite methods in your subclass, and allows you to swap out superclasses with minimal code changes.

What is super()?

100

A testing framework that provides a rich set of tools for constructing and running tests. Originally inspired by JUnit, this module supports test automation, supports test fixture, test cases, test suites, and test runners. 

What is unittest?

200

What will the following print?

i = '5'

int(i)

ord(i)

i = int(ord(i))

>>> print(i)

53, 

the ord() function returns an integer representing the Unicode character. 

200

Special methods that start and end with the double underscores. They are not meant to be invoked directly by you, but the invocation happens internally from the class on a certain action.

What are magic (dunder) methods?

200

How would you create an empty "dummy" class in Python?

class Class:

      pass

200

Showing only essential attributes and hiding unnecessary information is?

Abstraction


200

Python code in one module gains access to the code in another module by the process of this important statement, usually at the top of your file. It combines two operations; searching for the named module, and then binding the results of that search to a name in the local scope. 

What is an import statement?

300

Returns a list of valid attributes of an object.

What is the dir() method?

300
'5' + '5' = '55'

5 + 5 = 10

but why (explain) ?

The __add__ method behaves differently for different objects. For a string type, calling + concatenates the two. For an int type, calling + performs an addition operation. This is an example of Dynamic Method Dispatch, as python handles the different operations based on the object type. 

300

This formula is used to calculate the middle of an array during a binary search

mid = (high + low) // 2

300
A method that is shared among all instances of the object, but doesn't access any class members.

What is a static method?

300

The interpreter for Python was written in this language, which allows for dynamic memory allocation.

What is C?

400

Define anonymous functions, meant for one time use. Typically done in a single line for simple tasks for which creating an entire method is not necessary.

What are lambda functions?

400

This characteristic of OOP allows for the correct version of an overridden method to be called when an instance of a subclass is used to call it

What is polymorphism?

400

Write a function to return the max of two ints

 max length: 1 line

max = lambda a, b : a if (a > b) else b

400

In this type of inheritance, features of the base class and the derived class are further inherited into the new derived class. This is similar to a relationship representing a child and grandfather.

What is multilevel inheritance?

400

List all bitwise operations

&& (AND)

| | (OR)

^ (XOR)

~ (NOT)

<< (Left Bit Shift)

>> (Right Bit Shift)

500

x = ["a", "b", "c"]

y = ["a", "b", "c"]

print(x is y and x ==y)

What will this output?

False

Although they are equivalent, they do not point to the same object in memory. So x == y will return True, but the "is" operator compares the memory addresses of the two objects, which will return False, so this returns False as a whole because of the "and" operation.

500

Determines the order in which Python looks for a method in a hierarchy of classes.

What is Method Resolution Order?

500

What are the properties of a BST? 

Binary Search Tree is a node-based binary tree data structure which has the following properties:  

- The left subtree of a node contains only nodes with keys lesser than the node’s key.

- The right subtree of a node contains only nodes with keys greater than the node’s key.

- The left and right subtree each must also be a BST. 

500

What is the base Object class here?

class F(O):pass

class E(O):pass

class D(O):pass

class C(D,F):pass

class B(D,E):pass

class A(B,C):pass

In this case, O is the base object class. The MRO will look something like this: 

    O

/    |     \

D    E     F

 |/ \     /

 B       C

   \    /

      A

500

What is the runtime complexity of a standard Binary Search?

a. O(NlogN)

b. Θ(logN)

c. O(N)

d. O(N^2)

A binary search, in the worst case, runs in O(logN) time, which is implied by big Theta Θ.