A Quick Summary
In this chapter, you’ve learned several things about abstraction in general, and functions in particular:
Abstraction. Abstraction is the art of hiding unnecessary details. You can make your program more abstract by defining functions that handle the details. Function definition. Functions are defined with the def statement. They are blocks of statements that receive values (parameters) from the “outside world” and may return one or more values as the result of their computation.
Parameters. Functions receive what they need to know in the form of parameters—variables that are set when the function is called. There are two types of parameters in Python, positional parameters and keyword parameters. Parameters can be made optional by giving them default values.
Scopes. Variables are stored in scopes (also called namespaces). There are two main scopes in Python—the global scope and the local scope. Scopes may be nested.
Recursion. A function can call itself—and if it does, it’s called recursion. Everything you can do with recursion can also be done by loops, but sometimes a recursive function is more readable.
Functional programming. Python has some facilities for programming in a functional style. Among these are lambda expressions and the map, filter, and reduce functions.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Rights and permissions
Copyright information
© 2005 Magnus Lie Hetland
About this chapter
Cite this chapter
(2005). Abstraction. In: Beginning Python. Apress. https://doi.org/10.1007/978-1-4302-0072-7_6
Download citation
DOI: https://doi.org/10.1007/978-1-4302-0072-7_6
Publisher Name: Apress
Print ISBN: 978-1-59059-519-0
Online ISBN: 978-1-4302-0072-7
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)