Arvutiteaduse instituut
  1. Kursused
  2. 2024/25 sügis
  3. Programmeerimise alused (MTAT.03.236)
EN
Logi sisse

Programmeerimise alused 2024/25 sügis

  • 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 >

  • Arvutiteaduse instituut
  • Loodus- ja täppisteaduste valdkond
  • Tartu Ülikool
Tehniliste probleemide või küsimuste korral kirjuta:

Kursuse sisu ja korralduslike küsimustega pöörduge kursuse korraldajate poole.
Õppematerjalide varalised autoriõigused kuuluvad Tartu Ülikoolile. Õppematerjalide kasutamine on lubatud autoriõiguse seaduses ettenähtud teose vaba kasutamise eesmärkidel ja tingimustel. Õppematerjalide kasutamisel on kasutaja kohustatud viitama õppematerjalide autorile.
Õppematerjalide kasutamine muudel eesmärkidel on lubatud ainult Tartu Ülikooli eelneval kirjalikul nõusolekul.
Courses’i keskkonna kasutustingimused