Python Basics Flashcards

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

Declarative Knowledge

A

A statement of fact

it does not tell you have to do stuff

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

Imperative Knowledge

A

A recipe or “how-to”
(this tells you how to do something)
Also know as an algorithm

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

What is a recipe?

A

1) A sequence of simple steps
2) Flow of control that specifies when each step is executed
3) Determining when to stop

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

Syntax

A

Is passing of a sentence/string

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

Static semantics

A

Is which syntactically valid strings have meaning

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

Semantics

A

Is the meaning associated with syntactically correct string of symbols with no static semantic errors

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

Program

A

Is a sequence of definitions and commands

  • definitions are evaluated
  • commands are executed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Commands

A

Statements - instruct interpreter to do something

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

Data objects

A

is what the program is manipulating

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

Objects are

A

scalar (cannot be subdivided)

non-scalar (have internal structure that can be accessed)

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

Object type

A

defines what the programs can do to them

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

Scalar objects in Python

A
  • Integers (int)
  • Real numbers (float)
  • Boolean (bool)
  • Special (NoneType)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

cast

A

convert objects of one type to another

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

combine objects and operators

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

operator precedence without parentheses

A
**
*
/
\+ and -
execute left to right
parentheses always have top priority and get done first and will be evaluated inside out.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

assignment

A

equal sign is an assignment of a value to a variable name

  • value stored in computer memory
  • an assignment binds name to value
  • retrieve value associated with name or variable by invoking the name
17
Q

Abstracting expressions

A
  • give names to values of expressions
  • reuse names instead of values
  • easier to change code later
18
Q

Branching

A
  • make a choice and do different things
  • each statement gets executed once
  • runs in constant time
19
Q

Variables (bindings)

A
  • name (descriptive, meaningful, re-read code, no keywords)
  • value (can be updated)
  • right hand side -> VALUE
  • left hand side -> VARIABLE
20
Q

String

A
  • letters, special characters, spaces, digits
  • enclosed in quotation marks or single quotes
  • concatenate strings by using the + operator
21
Q

overloaded the + operator

A

is when using the + sign to concatenate two or more strings together

22
Q

for loops

A
  • known number of iterations
  • can end early via break
  • use a counter
  • can rewrite a for loop using while loop
23
Q

while loops

A
  • unbound number of iterations
  • can end early via break
  • can use a counter, but must initialize before loop and increment inside loop
  • may not be able to rewrite a while loop using a for loop
24
Q

compare/test object type

A
  • type(object) returns the type of the object

- isinstance(object, type) testing if an object is of a certain type

25
Q

iterative code

A
  • branching structures (conditionals) can jump to diff. pieces of code based on a test - programs are constant time
  • looping structures (like while or for) let us repeat code until a condition is satisfied - programs take time depending on value of variables as well as length of program.
26
Q

Useful for a decrementing function

A
  • maps set of program var into an integer
  • when loop is entered, value is non-negative
  • when value is <= 0, loop terminates and
  • value is decreased every time through loop
27
Q

Need a loop variable

A
  • initialize outside loop
  • changes within loop
  • test for termination depends on variable
28
Q

Guess-and-Check

A
  • guess a value
  • check if the solution is correct
  • keep guessing until find solution or guessed all values
  • the process is exhaustive enumeration