1/7
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
static method
called on CLASS as whole, NOT on object of class
has nothing to do w object specific data, only on the class
doesnt need self param
class method
applies on CLASS as a whole, not objects
takes cls as a param bc needs class for smth
useful for creating factory methods (create objs of a type
class attributes
variables that belong to the class itself, not to any instance.
shared among all instances of the class, often used for constants or default values.
__dict__
a special attribute of a class or instance that holds a dictionary containing all its writable attributes. Provides a way to dynamically access or modify the attributes of an object.
iterable
smth that can be ITERATED over
it knows HOW TO GIVE U AN ITERATOR
can use a for loop or iter() over them
ex: lists, strings, ranges, tuples, etc
like a book (smth u can flip the pgs thru)
__iter__(self)
what MAKES the OBJECT iterable
by returning ITERATOR for that object
how to use: iterator = iter(object)
like the process of getting a new bookmark for the book
iterator
the obj that produces a sequence of values, 1 at a time
manages the itertion process
keeps track of where u are rn, how to give u the next element
generator
function that produces sequence of results 1 at a time, instead of all at once (lazy evaluation - only does work when its asked)
uses yield instead of return
yields a value, then pauses. always rememebers its exact state
O(1) MEMORY ONLY!
generators are also iterators