Skip to main content

Abstraction

  • Chapter
Beginning Python
  • 10k Accesses

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 34.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Rights and permissions

Reprints 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

Publish with us

Policies and ethics