Function in Python



A function is a set of codes which executes at a time and used to perform some actions




Function Syntax
Def: Key
Function Name
Input Values
Function Body
Return Value

Key    Name           Input          Body               ReturnValue

"def"  funcname "(" [parameter_list] ")" ":" suite
Function Code snippet
#Function without input/output
Definition
def my_function():
    print("Hello  Function!")
Calling
my_function()

#Function with input
def printhello( str ):   "This is hello test print  function"
   print str
   return;

printhello(“hello”)
# Function with return
def sum_two_numbers(a, b):
    return a + b
 sum_two_numbers(5,7)

 # Function with input/output
def printhello( a, b ):
return a + b;


Recursive functions
def factorial(n):
    if n == 1:
        return 1
    else:
        return n * factorial(n-1)

factorial(5)



Function Arguments
Required arguments
Keyword arguments
Default arguments
Variable-length arguments
Function in Python Reviewed by Rupesh on 21:50 Rating: 5

No comments:

All Rights Reserved by Technology from Developers Eye © 2014 - 2015
Powered By Blogger, Designed by Aadics
Disclaimers:: The information provided within this blogsite is for general informational purposes only. While we try to keep the information up-to-date and correct, there are no representations or warranties, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information, products, services, or related graphics contained in this blogsite for any purpose.The author does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause.

Contact Form

Name

Email *

Message *

Powered by Blogger.