Python Flashcards
How is Python interpreted?
Dynamically, which means the code is interpreted at runtime. There is no compiling before execution and no linking.
What is the type system for Python?
Duck typing, which means it doesn’t matter if you tell me it is a duck, if it quacks, it is a duck. So the code is not constrained by data types, but it executes an action based on the type of built-in objects being processed.
In other words, the type of an object/expression is determined by the operations involved.
What is the cons of duck typing?
No compile time and runs right away, so there are very few checks that can be done. Need a lot of testing just to be safe.
What are the other implementations of Python (CPython)?
PyPy, Cython, Jython
What is IPython?
An interactive shell for Python. Can run in shell with $ipython
What is the pros of using Jupyter Notebook?
Collaboration on computational documents, markdown for documentation, many new libraries for data processing,
What is a unit test?
A unit test is used to test the behaviour of a unit of functionality.
What is the module for unit test
unittest
If we want to test whether add(3, 5) returns 8, what would the unit test look like?
def test1(self):
self.assertEqual(add(3, 5), 8)
If we want to test whether fat(“Benson”) returns false, what would the unit test look like?
def test2(self):
self.assertFalse(fat(“Benson”)
How to express not a-z in regex?
[^a-z]
What is + in regex?
1 or more
What is * in regex?
0 or more
How to find “ethelia0” from a string?
import re
r = re.compile(r”ethelia[0-9]+”)
v = r.findall(“My name is ethelia”)
What is virtualenv?
It is a tool to create isolated python virtual environments. It is not a virtual machine! The benefits of having this is when your code needs specific libraries and versions of these.
Different environments provide different libraries and these can change when the system administer updates the system. Using virtualenv ensures that if it works on this machine, it works on others.