Once a function is created you can call it by writing function_name() itself or another function/ nested function. Use a def keyword to declare or write a function in Python.
def function_name():
Statement1
# directly call the function
function_name()
The “def ” statement followed by the function name and parentheses ( () )
Python Call Function
Simple example code.
def MyFun():
print("Hello World")
print("Call function")
MyFun()
Output:
Calling Nested Function in Python
Call the outer and the inner functions to execute the statement.
def OutFun():
print("Call outer function")
def InFun():
print("Call inner function")
InFun()
OutFun()
Output:
Call inner function
Call outer function
Write a program to call a function inside the class
class Student:
Roll_no = 100
name = "John"
def show(self):
print("Roll no: %d\nName of student is %s" % (self.Roll_no, self.name))
# object
s = Student()
s.show()
Output:
Do comment if you have any doubts or suggestions on this Python function 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.