Foundation Theory Flashcards

1
Q

Features of Python

A
  • High level (high level of abstraction, much easier to understand and less complex)
  • General purpose (versatile)
  • Concise and readable syntax
  • Many modules and libraries
  • Large and supportive community
  • Works cross platform
  • Object oriented (you can create reusable blocks of code to create specific objects with shared attributes)
  • Interpreted (executed line by line)
  • Dynamically typed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Differences between Python 2 and Python 3

A

Python 2: released in 2000, no longer widely in use.
Python 3: released in 2008, forward-compatible (only future versions are supported)
Print keyword is a function (previously a statement)
Strings stored as UNICODE (previously ASCII)
Two integers divided -> float (previously integer)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is PEP 8?

A

A document explaining guidelines and best practice on writing Python code, designed to improve readability and consistency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a program?

A

A sequence of ordered instructions for a computer to perform.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a process?

A

An instance of a program running in a computer, the set of instructions currently being processed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a cache?

A

A cache is software or hardware used to store data temporarily so it can be retrieved quickly for future requests.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a thread, what is multithreading?

A

A thread is a single sequence of programmed instructions. Multithreading is multiple threads being executed at the same time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is concurrency and what is parallelism?

A

Concurrency = multiple overlapping tasks being completed by the same CPU, switching between them to make progress on more than one at a time.
Parallelism = multiple tasks run at the same time on different CPUs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is GIL and how does it work?

A

Global Interpreter lock - used by Python when dealing with processes, to ensure only one thread can be executed at a time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What do DRY, KISS and BDUF mean?

A

DRY - don’t repeat yourself, put reusable code in a function
KISS - keep it simple stupid, avoid overly complex code and stick to simple, efficient code.
BDUF - big design up front, design the overall structure of a system or programme before you start implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Garbage Collector and how does it work?

A

An automatic process that frees up memory by deleting objects that are no longer in use. It uses reference counting to keep track of the number of times an object is referenced.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How is memory managed in Python?

A

Python has automatic memory allocation and deallocation. It uses Garbage Collection and reference counting. Once an object has no references, the memory manager destroys the object.
Two parts of memory:
- The stack stores methods/method calls and references
- The heap stores objects and data structures

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a Python module?

A

.py file containing code which can be imported into another program. Usually contains a set of functions or code blocks that you want to reuse. This allows you to break down programs into more manageable and organised files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is docstring?

A

Strings used within functions, classes or methods immediately after the definition. They are then associated with their respective object as __doc__ attribute.

def addition(a*b):
‘’’
Takes integers a and b, returns the result of multiplying them together.
‘’’’’

print(addition.__doc__)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is pickling and unpickling?

A

A module used to serialise and de-serialize Python objects. Converts any type of object into byte streams (0s and 1s) and then back into an object. This allows us to transfer data between servers and systems, and store it in a file or database.
import pickle
pickle.dump
pickle.load

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the tools that help find bugs or perform static analysis?

A

Pychecker is open source tool for states analysis which detects bugs from the course code.
Pylint checks for errors, looks for type errors and makes recommendations on how to refactor code blocks. It can help improve code quality and ensure you comply with PEP-8 guidelines.

17
Q

How are arguments passed in Python?

A

Arguments are passed by reference - eg referring to a variable that already exists in a memory, rather than an independent copy of a variable.

18
Q

What are dictionary and list comprehensions in Python?

A

dictionary = {key: value for vars in iterable if condition == True}
list
list = [expression for item in iterable if condition == True]

19
Q

What is namespace?

A

Namespaces are structures used to organise the names assigned to objects. Namespaces are created as necessary and deleted when no longer needed.
Built-in: contains the names of built-in objects
Global - contains names defined at the level of the main program
Local - local names created inside a function
Enclosing - a function within a function

20
Q

What is pass in Python?

A

A null statement which is a placeholder for future code to avoid an error being raised where you are not allowed to have empty code.

21
Q

What is a unit test?

A

An approach to testing which looks at individual units of code to check the output is correct. This allows us to verify each individual part of the code is working as expected. The unittest module is a built-in framework to support testing.

22
Q

What is slicing?

A

A feature that allows us to extract part of an object. It uses the syntax object[start:stop:step]

23
Q

What is a negative index?

A

When you start indexing from the end of an iterable.

24
Q

How can the ternary operators be used?

A

Conditional expressions using a more concise syntax than if… else
[if_true] if [expression] else [if_false]

25
Q

Define *args, **kwargs and how we use it?

A

We use them to pass a variable number of arguments to a function.
*args mean non keyword arguments
**kwwargs means keyword arguments

26
Q

How are range and xrange different?

A

Both generate a list of integers, but xrange evaluates lazily, so it only computes the next value when needed rather than creating a list. This is more optimised and takes up less space in memory.

27
Q

What is Flask?

A

A Python module which is a web framework that makes it easier to develop reliable, scalable and maintainable web applications by providing reusable code and extensions for common operations.

28
Q

What are clustered and non-clustered indexes?

A

A clustered index defines the order in which records are inserted and stored. By default it is created on a primary key column, and values are sorted and stored based on their key values. There can only be one clustered index per table. A non-clustered index has a separate structure to the data rows - it contains the index’s key values which relate to the data row which contains each key value.

29
Q

What is deadlock and livelock?

A

Deadlock - two or more database transactions cannot make progress because they are both waiting for the other to release a lock. Livelock - two or more processes continually repeat the same interaction in response to each other, preventing them from completing a task. A series of overlapping locks keep on interfering with each other, holding up a transaction indefinitely.