Little Known Ways to PYTHON FUNCTION by shadbox

Total Blog Views: 49

Blog Status: publish

Created By: asad_fazlani Created at: 08-08-2021

Tags: python functions

Python Function :

  • Function is a block of reusable code or program  which can be called whenever required.
  • python allows us to divide a large program into the basic blocks of code known as function.
  • A function called multiple times.
  • python provide us various inbuilt function like print() , range() etc.which can called user defined function.
  • in python we can use def( ) keyword to define function.

Syntax :

     def function_name():
          statements....
          return  expression

Examples :

 

  • A simple Function without parameters 
     >>> def hello_world():
         print("Hello World")
 
 
     >>> hello_world()
     Hello World
     >>> 
 
  • function with one parameter.
     >>> a = 5
     >>> def num(a):
         print(a)
     >>> num(a)
     5
     >>> 
 
  • function with two parameter
     >>> def sum(a,b):
         return a + b
     >>> print(sum(10,20))
     30
     >>> 
 

Exercise : Comment your answer....Write a program to display number from 1 to 10 using function.


asad_fazlani

Technical Blogger at shadbox



Comments



  • swazahmad | almost 4 years ago
    Awesome Information Thanks For Sharing
Buy traffic for your website

About Shadbox

we have the “Get things executed” lifestyle at our place of work. There are not any excuses, no if’s or however’s in our dictionary. committed to navigating the ship of creativity to create cell answers, we resolve the real-lifestyles troubles of our clients and their clients. Our passion for work has won us many awards, year after 12 months.

Services

Downloads