Still confused about "self" in Python? Then watch this!

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024
  • Self is a mysterious thing when you start creating classes in Python. In this video you learn why methods have self as first parameter and how Python passes a value for it automatically when calling the method.
    D E E P E R D I V E:
    Take a deeper dive into self by learning how bound methods work in Python: • How bound methods are ...
    C H A P T E R S
    0:28 What is self?
    0:35 Why does a method have two parameters and when you call the method you only have to pass one argument?
    1:29 The instance and the arguments are packed into a method object
    F R O M T H E D O C S
    "If the name denotes a valid class attribute that is a function object, a method object is created by packing (pointers to) the instance object and the function object just found together in an abstract object: this is the method object. When the method object is called with an argument list, a new argument list is constructed from the instance object and the argument list, and the function object is called with this new argument list."
    docs.python.or...
    M Y O N L I N E T R A I N I N G
    🎓Like my style of teaching? Try free chapters of my online courses: pythonforevery...
    #pythonforeveryone #programming #self

ความคิดเห็น • 150