PROGRAMMING

m9/ PYTHON
REMEMBERS




CLASSES

p263 ! A programmer-defined type is called a class.
 
class Point:

    def get():
        return (1, 1)

print(Point.get()) # (1, 1)
A class definition cannot be empty. The body in this example is docstring that describe the class.
 
class Point:
    """ a 2D point """

p = Point()
A class is like a factory for creating objects. Because Point is defined at top level, its name contains __main__
 
class Point:
    """ a 2D point """

p = Point()
print(p)
    # <__main__.Point object at 0x7f0b0cd65940>

Questions    
Attributes

        A B C D E F
🔔
1/2