Python Flashcards

1
Q

Tuples

A
  • immutable objects
  • start at 0
  • can lookup but can’t change
  • more efficient but less flexible
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Lists

A
  • mutable
  • zero based
  • can be very flexible and has many functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Strings

A

“”
Zero index
Immutable

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

Reference Semantics

A

When assign var to another var it point to address

    1. Reference of name X is looked up
      1. The value at that reference is retrieved
      2. Calculation occurs producing new data element which is assigned to fresh memory location with new reference
      3. The name X is changed to point to this new reference
      4. Old data is garbage collected if no var still refers to it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

LEGB

A
  1. First search for local definition
  2. And if not found there go to Enclosing definition
  3. Not found there go to Global definition
  4. If not there then go to Built-in definition
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Local (function)

A

Names assigned in any way within a function and not declared global in that function

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

Enclosing function locals

A

Names in the local scope of any and all enclosing functions from inner to outer

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

Global (module)

A

Names assigned at the top level of a module file or declared global in def within the file

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

Built-in (python)

A

Names preassigned in the built in names module

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

Class

A

Is a special data type which defines how to build certain kind of object
-stores some data items that are shared by all the instances of this class

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

Instances

A

Are objects that are created which follow the definition given inside the class

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

Data attribute

A
  • var owned by a particular instance of a class
  • each instance has its own value for it
  • these are the most common kind of attribute
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Class attributes

A
  • owned by the class as a whole
  • all instances of the class share the same value for it
  • called “static” var
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

First-object

A
  • an argument to a function
  • a return value from a function
  • assigned to a variable
  • a part of container (tuple, list)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly