Institute of Computer Science
  1. Courses
  2. 2024/25 fall
  3. Introduction to Programming (MTAT.03.236)
ET
Log in

Introduction to Programming 2024/25 fall

  • Home Page
  • Introduction
  • Expressions
  • Conditional Execution
  • Functions
  • Iterations
  • Strings
  • Files
  • Lists
  • Graphics?
< previousTable of Contentsnext >

4.2 TYPES OF FUNCTIONS

BUILT-IN FUNCTIONS

As you already have learned, Python's built-in functions are a set of pre-built functions that are readily available for use. Some examples include the following.

  • print() - outputs data to the console
  • int(), str(), float() - convert objects to desired data types
  • input() - take input from a user.

IMPORTED FUNCTIONS

Another group of functions can be defined as imported functions. These libraries are made available for us to use by the Python community or other third parties. Some examples would be the following.

  • random - library that contains functions such as randint() that allows you to generate random numbers.
  • math - a collection of mathematical functions, such as sqrt(), factorial(), log(), etc.

USER-DEFINED FUNCTIONS

User-defined functions in Python are custom functions that you write to solve tasks. They can also incorporate built-in or imported libraries within them.


# Function that calculates the square of the provided number
def square_of(number):
	return number ** 2

print(square_of(10)) # Outputs 100

KEY THINGS TO REMEMBER

  • Built-in functions are integrated into the Python interpreter, so they are available in any Python environment without the need to import additional libraries.
  • Imported functions are functions made available by third parties. To access them you need to explicitly import these libraries or specific functions as shown in previous chapters.
  • The programmer writes user-defined functions to perform specific tasks that extend beyond the scope of Python's built-in functions.
< previousTable of Contentsnext >

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment