Skip to main content

Functions

  • Chapter
  • First Online:
The Python Workbook

Part of the book series: Texts in Computer Science ((TCS))

  • 12k Accesses

Abstract

Using functions effectively makes larger programs easier to develop, test, debug, and enhance.

  • Functions let a programmer write code once and then call it from many locations.

  • Functions allow individual parts of a program to be tested separately.

  • Functions allow details to be set aside once part of a program is complete.

These benefits are achieved by allowing a programmer to name a collection of Python statements and set them aside for later use. Then, whenever those statements are needed, they can be executed. When the statements in a function finish executing, control returns to the location where the function was called and the program continues to execute from that point. A function can be called many times from many different locations within a program.

This chapter explores defining functions, calling functions, and returning values from functions. Each of its 25 exercises is an opportunity for the reader to put these concepts into practice.

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

Access this chapter

Subscribe and save

Springer+ Basic
EUR 32.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 49.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 54.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Ben Stephenson .

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Springer Nature Switzerland AG

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Stephenson, B. (2019). Functions. In: The Python Workbook. Texts in Computer Science. Springer, Cham. https://doi.org/10.1007/978-3-030-18873-3_4

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-18873-3_4

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-18872-6

  • Online ISBN: 978-3-030-18873-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics