Skip to content

Python class function

  • by

Python class function is simply a function that is defined within the scope of the class. The functions can be defined within the class exactly the same way that functions are normally created.

class Name_of_Class:
   <methods/Function>

Python class function example

Simple example code.

# python class
class University:

# Function
def sayHello(self):
return "Hello from out University"


# class object
uni = University()
print(uni.sayHello())

Output:

Python class function

Do comment if you have any doubts or suggestions on this Python class topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

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

Continue reading