Skip to main content
  • 11k Accesses


A function is a part of a computer program where a number of programming statements is clubbed as a block. It can be called when desired. This enables a modular approach to programming tasks and has become very popular among programmers nowadays since modules can be edited with ease. Functions receive input parameters and return output parameters. When a function is being used, the function name is called along with values for input parameters. After execution, a set of output parameters is returned. Python functions can be defined at any place in the program, regardless of the place from where they are being called. They can even be defined as a separate file individually or in a combined manner. Also, they can be called any number of times or they may not be called at all, as per the user’s requirements.

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

Access this chapter

Institutional subscriptions

Author information

Authors and Affiliations


Rights and permissions

Reprints and permissions

Copyright information

© 2018 Sandeep Nagar

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Nagar, S. (2018). Functions and Loops. In: Introduction to Python for Engineers and Scientists. Apress, Berkeley, CA.

Download citation

Publish with us

Policies and ethics