DelphiDelphiVCLLearn PythonPythonPython GUIWindows

This Is How Python’s Self Works In Windows Development

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

Related posts
AndroidCodeDelphiDelphiFMXIDELearn PythonProjectsPythonPython GUI

How To Create A Calculator App Using Python GUI?

DelphiFMXDelphiVCLNewsPythonPython GUI

Introducing Python 3.11 And Documentation Support To The DelphiFMX And DelphiVCL GUI Python Packages

AndroidCodeDelphiDelphiFMXLearn PythonPythonPython GUI

How To Create A Tic-Tac-Toe Game Using Delphi Python EcoSystem

CodeDelphiDelphiFMXPythonPython GUI

How To Write A Simple Todo Gui Application Using Delphifmx

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

pt_BRPortuguese