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 Python's 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 Python's 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 Python's 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.

close
Related posts
Learn PythonPythonPython GUIVideos

This Is How To Create A Python Gui With PyQt5

Python GUI

What Are Python Debugging Tools: A Simple Definition

Learn PythonPythonPython GUIVideos

How To Make A Python GUI For An ATM System

Python

10 Resources That'll Make You Better At Python Programming Software

Leave a Reply

Your email address will not be published.

en_USEnglish