Functions in python
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Functions in python

Functions in python

Statistics

Views

Total Views
289
Views on SlideShare
275
Embed Views
14

Actions

Likes
0
Downloads
2
Comments
0

1 Embed 14

http://www.ustudy.in 14

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Functions in python Presentation Transcript

  • 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. FUNCTIONS IN PYTHON Shafeeque shafeequemonp@gmail.com www.facebook.com/shafeeque monp pambodan twitter.com/shafeequemonp in.linkedin.com/in/shafeequem onp 9809611325
  • 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. 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. 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. 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. 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. 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