DelphiDelphiVCLLearn PythonPythonPython GUIWindows

This Is How Python’s Self Works In Windows Development

This Is How Pythons Self Works In Windows Development

Whenever object-oriented programming is done in Python, then we will often come across the self method as their first parameter. This article explains the main concept of self method in Python for Windows development.

self represents the instance of the class in Python. By using the “self” keyword we can access the attributes and methods of the class in Python. It binds the attributes with the given arguments.

The reason you need to use self because Python does not use the @ syntax to refer to instance attributes. Python decided to do methods in a way that makes the instance to which the method belongs be passed automatically, but not received automatically: The first parameter of methods is the instance the method is called on.

Here is the basic example of how we can use self keyword:

The output in PyScripter IDE:

This Is How Pythons Self Works In Windows Development A Pyscripter results window showing the printed results of the code example

Here is another example:

The output in PyScripter IDE:

This Is How Pythons Self Works In Windows Development A PyScripter results window showing cars enumerated and printed out

Note: Self is a convention and not a real Python keyword. self is a parameter in function and the user can use another parameter name in place of it. But, it is advisable to use self to increase our code readability.

The following code is the working example of using self parameter in the context of creating GUI using DelphiVCL library:

And here is the GUI result:

This Is How Pythons Self Works In Windows Development An example Windows GUI form

You can browse more complex demo here.

 

Check out DelphiVCL which easily allows you to build GUIs for Windows using Python.

Related posts
CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And OpenCV Library?

CodeIDEProjectsPythonWindows

Unlock the Power of Python for Deep Learning with Radial Basis Function Networks (RBFNs)

CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And NumPy Library?

CodeIDEProjectsPythonWindows

Unlock the Power of Python for Deep Learning with Generative Adversarial Networks (GANs) - The Engine behind DALL-E

Leave a Reply

Your email address will not be published. Required fields are marked *