Python Functions

A function is a group of related statements or blocks of codes that perform a specific task.

In python, we create a function using the “def” keyword. At the end of function use colon(:) mark and write statements inside it.

return(optional) statement use return value.

>>> def name(name):

            print(“hi”+ name +”kumar”)

Calling function

Calling function written using function name with parenthesis.

>>> def name(name):

          print(“hi”+ name +”kumar”)

      name()

Calling function using parameters

>>> def name(name):

          print(“hi”+ name +”kumar”)

      name("naveen")

Calling function using parameters with default value

>>> def name(name = "naveen"):

          print(“hi”+ name +”kumar”)

      name()

How return value using function

To return value in function return keywork is used.

>>> def value(a):

          return a

      value(5)

Way to send argument value

By key as argument

>>> def using_key(name3,name2,name1):

          print("my friend name is " + name3)

      using_key(name1 = "naveen", name2 = "sachin", name3 = "jitendra")

By arbitrary argument

When need pass multiple arguments in function then we define the argument name with (*)

>>> def using_key(*name):

          print("my friend name is " + name3)

      using_key("naveen", "sachin", "jitendra")

Recursive function

Python supports recursive function when need to execute value recursively.

Contact Us

Tel: (+91) 0120  4118730  

Time :   10 : 00  AM -  08 : 00 PM IST 

Registered address: G-69, Sector 63, 

 Noida - 201301, India

We Provide Services Across The different countries

USA    Australia   Canada   UK    UAE    Singapore   New Zealand    Malasia   India   Ireland   Germany

CodersArts is a Product by Sofstack Technology Solutions Pvt. Ltd.

  • CodersArts | Linkedin
  • Instagram