Unit 1: Introduction to Python Flashcards

1
Q

Who designed Python?

A

Guido van Rossum

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

When did Python first appear?

A

1991

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

Computer program

A

Consists of a collection of commands, usually stored in a file (or set of files).

Rather than typing out the commands each time we want to execute them, we simply run the program.

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

Contrast imperative vs declarative programming

A

With imperative programming, you tell the compiler what to happen step-by-step.

With declarative programming, you write code that describes what you want, but not necessarily how to get it.

E.g.:

Declarative: “Give us every odd number in this collection”
Imperative: “Step through this collection. Check this item. If item % 2 == 0, add it to the result collection”.

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

6 Strengths of Python as a programming language

A
  • It’s easy to learn the basics.
  • It enables smooth progression from simple to complex programming.
  • Widely used.
  • Huge number of “packages” are available to support specific types of programming.
  • Python language provides convenient constructs for many high-level programming ideas.
  • Python strikes a good balance between theoretical elegance and practical utility.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

5 Weaknesses of Python as a programming language

A
  • May be too slow or inefficient for certain kinds of applications.
  • Some programmers don’t like the use of indentation to specify program structure.
  • Python does not keep track of or place restrictions on the type of a variable.
  • There are a huge number of different ways to do programming tasks, including very simple ones.
  • Python does not enforce modularity (though it does support it). This can potentially lead to maintainability problems, especially in a large system.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Intergrated Development Environment

A

A software tool that is designed to support the whole process of creating programs, including editing, running, and debugging, and also organising and combining different program components.

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

2 Advantages of server-based implementation of a programming interface

A
  • The server can either be running locally on the same machine as the browser, or remotely on another machine.
  • Multiple different machines (and people) may connect to the same server and have access to the same code, allowing collaborative development.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Literate programming

A

The purpose, functionality and logic of a program are explained by means of natural language descriptions that are included with the actual source code of the program.

In other words, the executable code of a program is shown with documentation of what it is and how it works.

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

6 General properties and capabilities of notebook programming environments

A
  • The interface is web-based.
  • Code execution and file storage are handled via a server.
  • Code cells can be executed either individually one at a time, or all code in the notebook can be executed.
  • Code output will display below each code cell after it is run.
  • When markdown cells are executed, they are rendered into the format specified by the markdown notations within the cell.
  • There are a wide variety of other commands such as: file loading and saving, cutting, pasting, searching, clearing output and restarting.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

5 Advantages of notebook-style programming

A
  • Notebooks provide a convenient way of planning and documenting code.
  • Because documentation is within the same file as the code, it’s less likely to be forgotten or ignored.
  • The division of code into cells is well-suited to a pipeline style of programming, where computational processing and/or data analysis proceeds in a series of steps. This division can make programming easier, since each step is a small and relatively simple part of a larger more complex computation.
  • Because program output can be nicely displayed, the notebook can also function as a report that presents and explains the results that have been obtained from the code.
  • The ability to include nicely formatted explanations, hyperlinks and images along with the code make notebooks an excellent medium for sharing information, as well as teaching and learning.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

3 Disadvantages of notebook programming

A
  • They only provide a limited subset of the system development functionality that is available in advanced non-notebook integrated development environments.
  • They do not provide good support for developing large systems that involve many complex components.
  • They do not promote a good style of structured programming. This is because the linear execution of small program snippets within a notebook does not motivate attention to code structure and modularity.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Variables

A

Words in a program’s code that are used to stand in place of some value.

They may be thought of as referring to or naming their value.

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

Rules for variable names in Python

A

A variable name can consist of any sequence of letters and digits and can also contain the underscore symbol.

Even though variable names can contain digits, the first symbol cannot be a digit.

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

Operator

A

This term typically refers to the most basic types of manipulation, such as mathematical operations.

These are often represented by specific symbols, such as +, *, -, …

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

Method

A

The term method is used in object-oriented programming languages (including Python) to describe a function that is intimately connected with some type of data that has been defined as a class.

.(, …, )

17
Q

‘procedure’ vs ‘function’

A

Historically, the word ‘function’ was typically used for an operation that returns a result, whereas ‘procedure’ meant an operation that produced some effect without returning a value.

18
Q

4 Primitive types in Python

A
  • Numbers (integers, floats and complex numbers)
  • Booleans
  • String (sequences of character)
  • NoneType
19
Q

int

A

Integer valued number of unspecified length

20
Q

float

A

A floating point number, which is an approximate representation of a real number.

21
Q

complex

A

Python can handle complex numbers, which consist of a real and imaginary part.

22
Q

8 Mathematical operations in Python

A
  • Addition (x + y)
  • Subtraction (x - y)
  • Multiplication (x * y)
  • True division (x / y)
  • Floor division (x // y)
  • Modulo (x % y)
  • Negative (-x)
  • Power (x**y)
23
Q

6 Comparison operators in Python

A
  • Equality (==)
  • Inequality (!=)
  • Greater than (>)
  • Greater than or equal to (>=)
  • Less than (<)
  • Less than or equal to (<=)
24
Q

Modules vs Packages in Python

A

The term module technically refers to any code that is stored within a single file.

The term is particularly used when talking about the standard modules that are provided with Python or distributed within some package.

A package is just a collection of modules that are grouped and distributed together.

25
Q

String

A

Strings are sequences of character symbols.

When stored or processed by a computer, each character symbol will be represented as a sequence of one or more bytes, in accordance with some character encoding.

26
Q

Python characters vs strings

A

Most programming languages have distinct data types for characters and strings.

However, in Python, there is no separate data type for characters. A character is just a string of length 1.

27
Q

Container types in Python

A

These are general purpose (and extremely useful) ways to collect multiple types within some containing structure.

There are four major kinds:
- lists
- tuples
- dictionaries
- sets

28
Q

What is the difference between a tuple and a list?

A

Tuples and lists are exactly the same, except that tuples are immutable.

29
Q

What is the requirement for a dictionary key?

A

It needs to be hashable and immutable.

Tuples can be a dictionary key, lists cannot.

30
Q

What are the requirements for a dictionary value?

A

Dictionary values can be any Python object, including lists or other dictionaries.

31
Q

What is a class?

A

A class defines a complex data type that may incorporate multiple data components.

It may also define methods that specify operations on that data.

Classes can be used to define arbitrarily complex data types.

32
Q

What is an object?

A

An object is a particular instance of a class.

33
Q

The “is” relation in Python.

A

The “is” relation tells us whether two variables are pointing to the same memory address, i.e. whether these two variables reference exactly the same object.

E.g.
x = 5
y = 5.0

x == y # Returns True
x is y # Returns False

z = 5
x is z # Returns True

34
Q

Class attributes

A

Variables belonging to the class.

Every object that instantiates this class will have these variables. A class attribute has the same value across all objects that instantiate the class.

35
Q

Instance attributes

A

Variables representing traits that objects have.