Python
  Home arrow Python arrow Page 3 - Python 101 (part 6): Hedgehogs, Python...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Python 101 (part 6): Hedgehogs, Pythons And Funky Chameleons
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2001-07-16

    Table of Contents:
  • Python 101 (part 6): Hedgehogs, Pythons And Funky Chameleons
  • Cheating The Taxman
  • Talking Movies
  • Call Me Sometime
  • Return To Me
  • Tall, Dark And Handsome
  • Arguing Your Case
  • Enter The Funky Chameleon
  • Flavour Of The Month
  • Hip To Be Square

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Python 101 (part 6): Hedgehogs, Pythons And Funky Chameleons - Talking Movies


    (Page 3 of 10 )

    Let's take a simple example, which demonstrates how to define a function and call it from different places within your Python program:



    #!/usr/bin/python # define a function def greatMovie(): print "Star Wars" # main program begins here print "Question: which is the greatest movie of all time?" # call the function greatMovie() # ask another question print "Question: which movie introduced the world to Luke Skywalker, Yoda and Darth Vader?" # call the function greatMovie()
    Now run it - you should see something like this:

    Question: which is the greatest movie of all time? Star Wars Question: which movie introduced the world to Luke Skywalker, Yoda and Darth Vader? Star Wars
    Let's take this line by line. The first thing I've done is define a new function with the "def" keyword; this keyword is followed by the name of the function (and optionally, one or more arguments). All the program code attached to the function is then indented within this block - this program code could contain loops, conditional statements, or calls to other functions. In the example above, my function has been named "greatMovie", and only contains a call to Python's print() function.

    Here's the typical format for a function:

    def function_name(optional function arguments): 'comment' statement 1... statement 2... . . . statement n...
    The comment line above allows the developer to optionally include a description of the function; if I wanted to be really verbose, I could modify the function definition in the example above to read

    # define a function def greatMovie(): 'this prints the name of my favourite movie' print "Star Wars"

    More Python Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway