Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use of None and self keywords in method construction

I’m analyzing some old code that I’ve inherited, and I have a question about the use of "self" and "None" keywords, specifically in the following example:

def run(self) -> None:

I understand that the self keyword is similar to the "this" keyword in C++ in that, in conjunction with the dot operator, it allows us to access the attributes and methods of the class in question. What I’m really interested in is the use of "-> None" in the declaration of the method named "run." Is this in PEP 8 because I can’t find an example. I’m using Python 3.7, in case that matters.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is the purpose of writing a method in this manner? What does "-> None" do?

>Solution :

They’re called type hints, and they enable annotating the types of the parameters and return types of functions.

https://peps.python.org/pep-0484/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading