THINK Python Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Program

A

a sequence of instructions that specifies how to perform a computation. The computation might be something mathematical, such as solving a system of equations or finding the roots of a polynomial, but it can also be a symbolic computation, such as search- ing and replacing text in a document or something graphical, like processing an image or playing a video.

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

Input

A

Get data from the keyboard, a file, the network, or some other device.

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

Output

A

Display data on the screen, save it in a file, send it over the network, etc.

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

Math

A

Perform basic mathematical operations like addition and multiplication.

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

Conditional Execution

A

Check for certain conditions and run the appropriate code.

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

Repetition

A

Perform some action repeatedly, usually with some variation.

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

High-Level Language

A

A programming language like Python that is designed to be easy for humans to read and write.

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

Low-Level Language

A

A programming language that is designed to be easy for a computer to run; also called “machine language” or “assembly language”.

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

Portability

A

A property of a program that can run on more than one kind of computer.

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

Interpreter

A

A program that reads another program and executes it

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

Prompt

A

Characters displayed by the interpreter to indicate that it is ready to take input from the user.

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

Print Statement

A

An instruction that causes the Python interpreter to display a value on
the screen.

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

Operator

A

A special symbol that represents a simple computation like addition, multipli- cation, or string concatenation.

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

Value

A

One of the basic units of data, like a number or string, that a program manipulates.

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

Type

A

A category of values. The types we have seen so far are integers (type int), floating-
point numbers (type float), and strings (type str).

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

Integer

A

A type that represents whole numbers.

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

Floating-Point

A

A type that represents numbers with fractional parts.

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

String

A

A type that represents sequences of characters.

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

Formal Language

A

Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all program- ming languages are formal languages.

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

Token

A

One of the basic elements of the syntactic structure of a program, analogous to a word in a natural language.

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

Syntax

A

The rules that govern the structure of a program.

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

Parse

A

To examine a program and analyze the syntactic structure.

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

Bug

A

An error in a program.

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

Debugging

A

The process of finding and correcting bugs.

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

Variable

A

A name that refers to a value.

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

Assignment

A

A statement that assigns a value to a variable.

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

Keyword

A

A reserved word that is used to parse a program; you cannot use keywords like if, def, and while as variable names.

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

Operand

A

One of the values on which an operator operates.

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

Expression

A

A combination of variables, operators, and values that represents a single result.

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

Statement

A

A section of code that represents a command or action. So far, the statements we have seen are assignments and print statements.

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

Execute

A

To run a statement and do what it says.

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

Interactive Mode

A

A way of using the Python interpreter by typing code at the prompt.

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

Script Mode

A

A way of using the Python interpreter to read code from a script and run it.

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

Script

A

A program stored in a file.

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

Concatenate

A

To join two operants end to end.

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

Comment

A

Informationinaprogramthatismeantforotherprogrammers(oranyoneread-
ing the source code) and has no effect on the execution of the program.

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

Syntax Error

A

An error in a program that makes it impossible to parse (and therefore im- possible to interpret).

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

Exception

A

An error that is detected while the program is running.

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

Semantics

A

The meaning of a program.

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

Semantic Error

A

An error in a program that makes it do something other than what the programmer intended.

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

Method

A

A function that is associated with an object and called using dot notation.

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

Loop

A

A part of a program that can run repeatedly.

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

Encapsulation

A

The process of transforming a sequence of statements into a function definition.

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

Generalization

A

The process of replacing something unnecessarily specific (like a number) with something appropriately general (like a variable or parameter).

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

Keyword Argument

A

An argument that includes the name of the parameter as a “keyword”. page 33

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

Interface

A

A description of how to use a function, including the name and descriptions of the arguments and return value.

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

Refactoring

A

The process of modifying a working program to improve function interfaces and other qualities of the code.

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

Development Plan

A

A process for writing programs.
page 35

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

Docstring

A

A string that appears at the top of a function definition to document the function’s interface.

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

Precondition

A

A requirement that should be satisfied by the caller before the function starts.
page 36

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

Postcondition

A

A requirement that should be satisfied by the function before it ends.
page 36

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

Floor Division

A

//
Divides two numbers and rounds DOWN to the nearest integer.

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

Modulus Operator

A

%
Divides two numbers and returns the remainder.

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

Boolean Expression

A

An expression that is either True or False.

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

Relational Operator

A

One of the operators that compares its operands: ==, !=, >, <, >=, and <=.

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

Logical Operator

A

One of the operators that combines boolean expressions: and, or, not.

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

Conditional Statement

A

A statement that controls the flow of execution depending on some condition.

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

Condition

A

A boolean expression in a conditional statement that determines which branch runs.

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

Compound Statement

A

A statement that consists of a header and a body. The header ends with a colon (:). The body is indented relative to the header.

60
Q

Branch

A

One of the alternative sequences of statements in a conditional statement.

61
Q

Chained Conditional

A

A conditional statement with a series of alternative branches.

62
Q

Nested Conditional

A

A conditional statement that appears in one of the branches of another conditional statement.

63
Q

Return Statement

A

A statement that causes a function to end immediately and return to the caller.

64
Q

Recursion

A

The process of calling the function that is currently executing.

65
Q

Base Case

A

A conditional branch in a recursive function that does not make a recursive call.

66
Q

Infinite Recursion

A

A recursion that does not have a base case, or never reaches it. Eventually, an infinite recursion causes a runtime error.

67
Q

_ _ main_ _

A

(page 23)
A special name fr the topmost frame. When you create a variable outside of any function, it belongs to __main__.

68
Q

Temporary Variable

A

A variable used to store an intermediate value in a complex calculation.

69
Q

Dead Code

A

Part of a program that can never run, often because it appears after a return statement.

e.g. alternative conditionals

70
Q

Incremental Development

A

A program development plan intended to avoid debugging by adding and testing only a small amount of code at a time.

71
Q

Scaffolding

A

Code that is used during program development but is not part of the final version.

72
Q

Guardian

A

A programming pattern that uses a conditional statement to check for and handle circumstances that might cause an error.

72
Q

Update

A

An assignment where the new value of the variable depends on the old.
e.g. x = x + 1
which means “ get the value of x, add one, and then update the value of x with the new value”

72
Q

Reassignment

A

Assigning a new value to a variable that already exists.

72
Q

Increment

A

An update that increases the value of a variable (often by one).

73
Q

Object

A

Something a variable can refer to. For now (chapter 8), you can use “object” and “value” interchangeably.

73
Q

Iteration

A

Repeated execution of a set of statements using either a recursive function or a loop.

73
Q

Initialization

A

As assignment that gives an initial value to a variable that will be updated.

73
Q

Decrement

A

An update that decreases the value of a variable.

73
Q

Infinite Loop

A

A loop in which the terminating condition is never satisfying.

73
Q

what is the flow of execution for a while loop?

A
  1. Determine whether the condition is true or false.
  2. If false, exit the while loop and continue execution at the next step.
  3. If the condition is true, run the body and then go back to step 1.
74
Q

Algorithm

A

A general process for solving a category of problems.

75
Q

Sequence

A

An ordered collection of values where each value is identified by an integer index. A string is a sequence.

76
Q

Item

A

One of the values in a sequence.

77
Q

Index

A

An integer value used to select an item in a sequence, such as a character in a string. In Python, indices start at 0.

78
Q

Slice

A

A part of a string specified by a range of indices.

79
Q

Empty String

A

A string with no characters and length 0, represented by two quotation marks.

80
Q

Immutable

A

The property of a sequence whose items cannot be changed.

81
Q

Traverse

A

To iterate through the items in a sequence, performing a similar operation on each.

82
Q

Search

A

A pattern of traversal that stops when it finds what its looking for.

83
Q

Counter

A

A variable used to count something, usually initially at 0 and then incremented.

84
Q

Invocation

A

A statement that calls a method.

85
Q

Optional Argument

A

A function or method argument that is not required.

86
Q

what are some examples of string methods?

A

1) .upper()
2) .find()

87
Q

File Object

A

A value that represents an open file.

88
Q

Reduction to a Previously Solved Problem

A

A way of solving a problem by expressing it as an instance of a previously solved problem.

89
Q

Special Case

A

A test case that is atypical or non-obvious (and less likely to be handled correctly).

90
Q

List

A

A sequence of values.

91
Q

Element

A

One of the values in a list (or other sequence), also called items.

92
Q

Nested List

A

A list that is an element of another list.

93
Q

Accumulator

A

A variable used in a loop to add up or accumulate a result.

94
Q

Augmented Assignment

A

A statement that updates the value of a variable using an operator like +=.

95
Q

Reduce

A

A processing pattern that traverses a sequence and accumulates the elements into a single result.

96
Q

Map

A

A processing pattern that traverses a sequence and performs an operation on each element.

97
Q

Filter

A

A processing pattern that traverses a list and selects the elements that satisfy some criterion.

98
Q

Object

A

Something a variable can refer to. An object has a type and a value.

99
Q

Equivalent

A

Having the same value.

100
Q

Identical

A

Being the same object (which implies equivalence).

101
Q

Reference

A

The association between a variable and its value.

102
Q

Aliasing

A

A circumstance where two or more variables refer to the same object.

103
Q

Delimiter

A

A character or string used to indicate where a string should be split.

104
Q

range function

A

built-in python function. range returns a list of indices from 0 to n-1, where n is the length of the list.

105
Q

List Operations

A

The + operator concatenates lists.

The * operator repeats a list a given number of times.

106
Q

List Methods

A

append - adds a new element to the end of a list.

extend - takes a list as an argument and appends all the elements.

sort - arranges the elements in a list from low to high.

.sorted() - returns a new sorted list and leaves the original alone

107
Q

ways to delete elements from strings

A

1) pop()
2) del
3) remove()

108
Q

Caller

A

The caller of a function is the unit of program code in which the call to the function occurred. This can be another function, a method (a specific type of function) or, in Python, the code in the “top level” of a python source code file – generally referred to as a script. (stack overflow)

109
Q

Floor Division

A

supported in python.
using // instead of / returns the integer value of a quotient. it drops anything after the decimal.

Definition:
Floor division is a division operation that rounds the result down to the nearest whole number or integer, which is less than or equal to the normal division result. The floor function is mathematically denoted by this ⌊ ⌋ symbol.

110
Q

mapping (chapter 11)

A

a relationship in which each element of one set corresponds to an element of another set.

111
Q

dictionary

A

a mapping from keys to their corresponding values.

112
Q

Key-Value pair

A

the representation of the mapping from a key to a value.

113
Q

Item

A

In a dictionary, another name for a key-value pair.

114
Q

Key

A

An object that appears in a dictionary as the first part of a key-value pair.

115
Q

Value (chapter 11)

A

An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word value.

116
Q

Implementation

A

A way of performing a computation.

117
Q

Hashtable

A

The algorithm used to implement Python dictionaries.

118
Q

Hash Function

A

A function used by a hashtable to compute the location for a key.

119
Q

Hasable

A

A type that has a hash function. Immutable types like integers, floats, and strings are hashable; mutable types like lists and dictionaries are not.

120
Q

Lookup

A

A dictionary operation that takes a key and finds the corresponding value.

121
Q

Reverse Lookup

A

A dictionary operation that takes a value and finds one or more keys that map to it.

122
Q

Raise Statement

A

A statement that (deliberately) raises an exception.

123
Q

Singleton

A

A list (or other sequence) with a single element.

124
Q

Call graph

A

A diagram that shows every frame created during the execution of a program, with an arrow from each caller to each callee.

125
Q

Memo

A

A computed value stored to avoid unnecessary future computation.

126
Q

Global Variable

A

A variable defined outside a function. Global variables can be accessed from any function.

127
Q

Global Statement

A

A statement that declares a variable name global.

128
Q

Flag

A

A boolean variable used to indicate whether a condition is true.

129
Q

Declaration

A

A statement like “global” that tells the interpreter something about a variable.

130
Q

get method

A

Dictionaries have a method called “get” that takes a key and a default value. If the key appears in the dictionary, “get” returns the corresponding value; otherwise it returns the default value.

131
Q

Tuple

A

An immutable sequence of elements.

132
Q

Tuple Assignment

A

An assignment with a sequence on the right side and a tuple of variables on the left. The right side is evaluated and then its elements are assigned to the variables on the left.

133
Q

Gather

A

An operation that collects multiple arguments into a tuple. “*”

134
Q

Scatter

A

An operation that makes a sequence behave like multiple arguments.

135
Q

Zip Object

A

The result of calling a built-in function “zip”; an object that iterates through a sequence of tuples.

136
Q

Iterator (chapter 12)

A

An object that can iterate through a sequence, but which does not provide list operators and methods.

137
Q

Data Structure

A

A collection of related values, often organized in lists, dictionaries, tuples, etc.

138
Q

Shape Error

A

An error caused because a value has the wrong shape; that is, the wrong type or size.

139
Q
A