oop terms python

studied byStudied by 2 people
0.0(0)
Get a hint
Hint

what is a class

1 / 6

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

7 Terms

1

what is a class

a class is a blueprint or instruction manual for an object

New cards
2

what is an object

an object is a manipulative structure which can be used to simplify tasks in coding by using data attributes (connected to instances) passed into the class (via init function). Then the data attributes can be used in methods

New cards
3

what are instances

instances is kind of like a data type that holds attributes of something (includes different information about one single thing - the instance)

ex. we define the instance item1 into the Item class that holds the parameter of itself as self and then we can pass on more parameters (attributes of the instance) to define in the init method

New cards
4

what are data attributes

data attributes are properties of the instances

ex. item1.price where price is the attribute assigned after the “.” indicator, we can instead put this into the parantheses when putting the instance in the class and define later in init method

New cards
5

what is a method

a method is a function in a class that uses the instances and their properties

New cards
6

what is the method init and what is it used for

the method init is used to define all the attributes of an instance at once before the other methods in a class. outside of the class we pass paramaters in the Item() class when defining the instance into the class, so ex of the parametrs being pushed is

item1 = Item(“Phone”, 100, 5)

where the first paramater before phone is intiially the name of the instance, then the second parameter i guess is “phone” as the name of the item, 100 being the price, and 5 being the quantity

then we can define the attributes in the init function within the class where we assign it like this:


def —init—(self, name, price, quantity):

self.name = name

self.price = price

self.quantity = quantity

this shows that when we define the init function to initialize the attributes we pass the four parameters from the line outside the class into the init function, self being the instance item1 itself, then the name, price, and quantity. then we say self(variable for item1).name = name which is the value passed.

New cards
7
New cards

Explore top notes

note Note
studied byStudied by 3 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 12 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 12 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 8 people
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 175 people
Updated ... ago
5.0 Stars(9)
note Note
studied byStudied by 57 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 11 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 22444 people
Updated ... ago
4.9 Stars(114)

Explore top flashcards

flashcards Flashcard60 terms
studied byStudied by 5 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard160 terms
studied byStudied by 60 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard29 terms
studied byStudied by 19 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard22 terms
studied byStudied by 29 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard20 terms
studied byStudied by 1 person
Updated ... ago
5.0 Stars(1)
flashcards Flashcard50 terms
studied byStudied by 85 people
Updated ... ago
4.7 Stars(3)
flashcards Flashcard24 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard88 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(3)