Py Classes (U Bootc) Flashcards

1
Q

how to see all functions and attributes belonging to an object of a class?

A

]] dir( )

]] help( )

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

1) what are functions within a class be called?
2) are there differences between built-in fn and method?
3) how are methods called?

A

1) Methods
2) No diff in structure and build. The diff. in structure is that methods always has a starting param. ‘self’, which is not explicitly populated when the method is called. Also, methods are not independent as a function, but are used within the context of a Class
3) Available to a class’ objects through the dot notation

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

name 4 different Py Classes?

A

integer, lists, dictionaries, tuples, strings

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

what can object be said to be a combination of?

A

Data and functions; data held by the object, to which functions available to that object can be applied

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

how is Class defined?

A
]] class  Class_name( params ):
]] ''' < description > '''
]]    def \_\_init\_\_(self, params)
]]         param...
]]
]]    def method_name(self, params)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is the use of ‘pass’ within a Class definition for an object?

A

Allows an Object to be instantiated without crashing

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

how to assign instance variables to an object, to be populated at the time an instance of the object is created?

A

init function, a method, also called a constructor
]] def init( self, var1, var2 )
]] self.var1 = var1
]] self.var2 = var2

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

what is a Class variable?
how is it defined?
how is it called?
what are variables called within a Class?

A
1) a variable value common to all instances of the type of object. Values will be the same for all object instances of the class, they can therefore be considered as default value for instances within the class
2)
]] class Class_name( ... ):
]]    class_variable = var_value
3) Class variables are called with the dot.notation, as 
# Book class
]] class Book:
]]     material = "paper"

]] Book.material # “paper”

4) Variables are called Attributes

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

what is a difference between a Class variable and an Instance Variable?

A

A Class variable’s value is common to all instances of the Class object, instance variable values is specific to each instance, and what sets one instance apart from another instance

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

what is a method?

A

a function within a class, a function to manipulate the data within the class

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

what is common to all params of the same class’s methods?

A

all have the parameter self as the 1st parameter in the list of parameters, instantiated to the class by the init-method

  • self-var
  • class vars
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is the naming convention for Python Classes?

A

CapPhrase convention; no underscores, all words are capitalised

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