Skip to content

Functions & in built functions

surendrabisht edited this page Jul 11, 2020 · 13 revisions

Experience of functions till now

We have been using functions up till now even in basic programs but didn't realize it. Now, we will dig into this topic. we used print() ,input() function to print message, value to console screen and take user input in console screen. we re using these functions but we have not created it. Compiler uses the library which are by default imported to our code to use these functions.

Functions:

Any peace of code written for a specific and single purpose which can be further used can be described using name and the code is enclosed inside this function name. Every-time one wants to reuse the functionality implemented, can use this function by calling it and the piece of code will execute. In a way, this is used for code reuse and we don't have to write duplicate code every-time we need same functionality. In big systems, we have multiple instances where we need to run same piece of code for different scenarios or different purpose. So we enclose that logic in functions.
Function can have any combination of these characteristics i.e. can have 1,2,3 all of them or 1,2 or any combination:

  1. Function can take input .Function can need some parameters to do some processing.
  2. function can give output .These functions return values to the caller so that caller can use this calculated value from the function further.
  3. function can process something inside and don't give any output. These functions just do action.

Some in-built functions are :

  • dir()
  • help
  • range()
Clone this wiki locally