REMEMBER PYTHON

MINTE9
2REMEMBER




CLASSES

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

    def get():
        return (1, 1)

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

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

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

Questions    
No. 25   Attributes
CARD
24
32

        A B C D E F
🔔
1/2