1. Home
  2. Computing & Technology
  3. Python

Beginning Python: Putting It All Together With Syntax

From , former About.com Guide

5 of 10

Functions

Functions in Python are declared using the reserved word 'def'. If the function takes any arguments, these are enclosed in parentheses after the function name. As with other languages, the names given to the functions arguments are those used in the function code. In the rest of the program, they may be known by other names. What matters is not the precise variable name but the data type of the variable passed.

The code below illustrates how a function is defined and later called by the main program. Unlike C, Python requires that all functions be prototyped (i.e., be declared before being called in the main program).

def multiply(a,b):
c = a*b
return c

product = multiply (x,y)
Explore Python
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.