4.1 - Fundamentals of Programming Flashcards

(17 cards)

1
Q

Why use constants?

A
  • Difficulty to accidentally change value.
  • More readable in code (i.e. constant PI is better than the value 3.14…. every time!)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Function to convert between a character and its ASCII code in Python

A

ord()

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

Function to convert between an ASCII code and its corresponding character in Python

A

chr()

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

DateTime object to a string in Python

A

Using the datetime library:
datetime.strftime()

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

String to DateTime object in Python

A

Using the datetime library:
datetime.strptime()

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

Why use local variables?

A

Avoid taking up excess memory when they are not needed!

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

What is the call stack?

A

A stack data structure that stores information on the subroutines that have been called.

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

What info is stored on the call stack?

A

Return addresses - to ensure control is returned to the correct call.
Parameters.
Local variables - efficient method of storage is on the call stack.

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

What is recursion?

A

When a subroutine is defined in terms of itself.

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

3 characteristics of a recursive subroutine…

A
  1. Base case - when it will stop calling itself and begin returning values.
  2. If the base case is not met, the subroutine must call itself.
  3. The base case must be met after a finite number of calls.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Example of algorithms that are often implemented recursively

A

Traversal algorithms

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

What is encapsulation?

A

Putting data, along with methods that work on it, together in an object.

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

What is inheritance?

A

When an object takes methods/attributes from a parent object. An “is a” relationship.

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

What is aggregation?

A

One class is a collection of other classes. A “has a” relationship.

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

What is composition?

A

One class is a collection of other classes, but if the container class is destroyed, so will the contained classes.

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

What is polymorphism?

A

When a programming language deals with certain objects differently to other objects.

17
Q

What are the three principles of object oriented programming?

A
  1. Encapsulate what varies.
  2. Favor composition over inheritance.
  3. Program to interfaces, not implementation.