HomePython Python 101 (part 6): Hedgehogs, Pythons And Funky Chameleons
Python 101 (part 6): Hedgehogs, Pythons And Funky Chameleons
This week, Python 101 discusses how to abstract out parts of yourPython code into reusable functions, add flexibility to them by allowingthem to accept different arguments, and make them return specific values.Also included: a discussion of variable scope and functions to help youwrite your own functions. Confused? All is explained within...
If you've been paying attention these last few weeks, you should now know enough about Python to begin writing your own programs in the language. As a matter of fact, you might even be entertaining thoughts of cutting down your weekly visits to this Web site and doing away with this tutorial altogether.
Well, a very wise man once said that a little knowledge was a dangerous thing...and so, as your Python scripts become more and more complex, you're going to bump your head against the principles of software design, and begin looking for a more efficient way of structuring your Python programs.
Over the course of the next few articles, I'm going to take a look at the Python framework for basic software abstractions like functions and classes. Specifically, this tutorial will show you how to build your own functions, thereby adding an element of reusability to your code; you'll learn the difference between arguments and return values, find out how to handle function objects, and even visit some of the more important built-in methods.