Foundation Theory Flashcards
Features of Python
- 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
Differences between Python 2 and Python 3
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)
What is PEP 8?
A document explaining guidelines and best practice on writing Python code, designed to improve readability and consistency.
What is a program?
A sequence of ordered instructions for a computer to perform.
What is a process?
An instance of a program running in a computer, the set of instructions currently being processed.
What is a cache?
A cache is software or hardware used to store data temporarily so it can be retrieved quickly for future requests.
What is a thread, what is multithreading?
A thread is a single sequence of programmed instructions. Multithreading is multiple threads being executed at the same time.
What is concurrency and what is parallelism?
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.
What is GIL and how does it work?
Global Interpreter lock - used by Python when dealing with processes, to ensure only one thread can be executed at a time.
What do DRY, KISS and BDUF mean?
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.
What is Garbage Collector and how does it work?
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 is memory managed in Python?
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
What is a Python module?
.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.
What is docstring?
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__)
What is pickling and unpickling?
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