w7 Flashcards
(15 cards)
what is a class
class is a blueprint for creating objects. Objects are instances of classes that can contain both data (called attributes) and functions (called methods)
what is an instance
an individual object of a certain class
Procedural vs Object-Oriented Programming
Procedural - focuses on functions and variables separately
Object-Oriented - groups related functions and variables into “units” (objects
what does __init__ do
is called automatically to initialise object attributes when its created
- used for assigning values to instance/object properties
what does __str__ do
returns a user friendly string that reps an object
what does __add__ do
meaning of obj1 + obj2
what does __eq__
means obj1 == obj2
what does __sub__ mean
obj1 - obj2
what does __mul__ mean
means obj1 * obj2
whats Polymorphism
Refers to the ability of some bit of code to handle different data types
whats the polymorphic operator and what can it handle
’+’ is the polymorphic operator
it handles ints, strings, floats, lists
whats the polymorphic function and what can it handle
“len”
handles any object with a __len__ method
What is a method
a special kind of function that is defined in a class definition
repr() vs str() purpose
repr() makes the object into the string
str() demonstrates the string to a user
what is the polymorphic construct and what does it handle
for member in collection
handles any iterable