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

Python printing None in result , Why?

I am trying to understand Classes in python.

Question: Why I am getting None in the output?

Here is my code :

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

class Student:

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def show_student(self):
        print("Student Name:", self.name)
        print("Student Age: ", self.age)


first_student = Student("amit", 12)
print(first_student.show_student())

And here is the output.

C:\Python38\python.exe D:/LearningRoot/DirFirst/test.py
Student Name: amit
Student Age:  12
None

>Solution :

first_student.show_student() returns None, which is what all Python functions return if no explicit return value was specified. Therefore:

print(first_student.show_student())

This will evaluate to print(None).

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