Functions in python

312 views

Published on

Functions in python

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
312
On SlideShare
0
From Embeds
0
Number of Embeds
28
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Functions in python

  1. 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  2. 2. FUNCTIONS IN PYTHON Shafeeque shafeequemonp@gmail.com www.facebook.com/shafeeque monp pambodan twitter.com/shafeequemonp in.linkedin.com/in/shafeequem onp 9809611325
  3. 3. What is a Function? A function is a block of code that has a name and it has a property that it is reusable i.e. it can be executed from as many different points in Program as required Structure of a Function There are two main parts of the function. i.e:The function header and the function body. int sum(int x,int y) { Int a=0; a=x+y; return a }
  4. 4. Function Header: { Int a=0; a=x+y; return a } It has three main parts The name of the function i.e. sum The parameters of the function enclosed in paranthesis Return value type Eg:int sum(int x,int y) Function Body: What ever is written with in { } in the above example is the body of the function. Function Call: Function is called by function name i.e:Here,for eg: sum(1,2);
  5. 5. FUNCTION IN PYTHON: Defining a Function 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.
  6. 6. Syntax: def functionname( parameters ): "function_docstring" function_suite return [expression]def functionname( parameters ): "function_docstring" function_suite return [expression] def functionname (parameters): “function docstring” function_suite return [expression] def functionname( parameters ): By default, parameters have a positional behavior, and you need to inform them in the same order that they were defined. Example: def printme(str): “this prints the passed strings into this function” print str return Calling a Function: we can execute it by calling it from another function or directly from the Python prompt For above example,function can be called as printme(“hai friends!”)  output: hai friends!
  7. 7. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  8. 8. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com

×