Programming - python Flashcards
(27 cards)
Are lists mutable or immutable?
Mutable
Are tuples mutable or immutable?
Immutable
What type of language is python?
Interpreted, object oriented
What is the first item’s index in a list?
0
What defines scope in python?
Indentation
What is a function?
A block of code used to perform a single, well-defined task
What are some advantages of using functions?
Simpler program design, Simpler testing of small units of code, Simpler development, Simpler code sharing
If inn the function environment the parameters are assigned values from the data that is passed, what is this termed?
Call by value
If in the function environment the reference to the list is assigned, what is this termed?
Call by reference
What is recursion?
Recursion is a method where the solution to a problem is calculated from solutions of smaller instances of the same problem
What are the three rules of recursive functions?
A recursive function must have a base case
A recursive function must call itself (recursive case)
The recursive case must approach the base case
What are the main steps of reading data from a file?
Opening the file
Getting the data out & into some sensible structure
Validating and cleaning data
Closing the file
What does cleaning the data mean?
Removing any trailing whitespace and newline (\n)
Extracting data from each (comma-separated) line
What is the process of writing data to a file?
Open the file
Ensure data is in the right format
Write the data
Close the file
What is an object?
An object is a specific instance of a class
What is a class?
A class is a description, or template, for an object
What is abstraction?
We define a class using the minimum necessary data (state). We define the minimum set of methods as interface to the class
What is encapsulation?
We store data that represents the object (state) inside the class. We define methods that operate on that state inside the class
What is association?
A “uses” B
For general relationships described by one class using the functionalities provided by another class
Typically no strong relationship between the objects
What is composition?
A “has a” B
Composition is used more strictly, for the relationship between a whole thing and its component parts
What is inheritance?
A “is a” B
a class specialises a previously defined class
What is a library?
A library is an external source of code which you can import and reuse
What is a framework?
Frameworks are similar to libraries in that they contain external code
But, frameworks interact with your code in a different way: frameworks are much more structured and prescriptive, your code only implements defined parts of the framework
What does an API do?
An Application Programming Interface (API):
- Defines how separate software systems interact
- Enables communication between software systems
- Provides rules for how requests and responses are exchanged