FUNCTION IN PYTHON

SAIROSHNI



Function

  • A funtion is a named part of program with smaller size which is used to perform a specific task.  
  • It can be called any number of times.
  • The Def keyword is used to define a function.
  • Function block begin with the keyword Def followed by the function name and parentheses(()) ends with colon and followed by block of statements.

Creating A Funtion

def my_function(): #function header
print("hello world") #function body

Calling A Function

def my_function(): #function header
print("hello world") #function body

my_function()  #function call

Program Routine

In python,program routine are called as "function"
Function is majorly classified into two types:
  • Built-in function
  • User-defined function 

Built-In Function

Built-in function are built into an application and can be used by end users.
Python has several built-in functions,such as:
  • print()
  • input()
  • len()
  • clear()
  • copy()

User Defined Function

Users can create their own function called user defined function.

Additionally On Functions

  • Value returning function
  • non-value returning function
Generally, "return" statement is used values to the function call.

Value Returning Function:

In this type of function it return back some values to the function call.

Program:


  def myfunction(number):
      return 10*number
  print(myfunction(10))
  print(myfunction(20))
  print(myfunction(30))
  print(myfunction(40))
  print(myfunction(50))


Output:


  100
  200
  300
  400
  500

Non value Returning Function

This type of function does not return back any values to the function call.

Program:

def myfunction(number):

    print(5*number)

(myfunction(10))

(myfunction(20))

(myfunction(30))

(myfunction(40))

(myfunction(50))



Output:


50
100
150
200
250





More topic in Python

Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send