HomePagev2 Forums Python Discussions Def function in python

  • Def function in python

  • Karri Bindu Madhavi

    September 12, 2020 at 10:57 am

    A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.

    Defining a function:

    You can define functions to provide the required functionality. Here are simple rules to define a function in Python.

    –>Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).

    –>Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses.

    –>The first statement of a function can be an optional statement – the documentation string of the function or docstring.

    –>The code block within every function starts with a colon (:) and is indented.

    –>The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.


    def functionname( parameters ):



    return [expression]


    The following function takes a string as input parameter and prints it on standard screen.

    def printme( str ):

    “This prints a passed string into this function”

    print str


Log in to reply.

Original Post
0 of 0 posts June 2018