die Funktion
function
The specific task, purpose, or way something or someone works.
Die Hauptfunktion des Herzens ist es, Blut durch den Körper zu pumpen.
The main function of the heart is to pump blood through the body.

function
Loading your saved state.
function
The specific task, purpose, or way something or someone works.
Die Hauptfunktion des Herzens ist es, Blut durch den Körper zu pumpen.
The main function of the heart is to pump blood through the body.

The noun 'die Funktion' (function) is closely related to the verb 'funktionieren' (to work/function). If something has a function, then it should also function.
Die Kaffeemaschine hat viele Funktionen, aber sie funktioniert nicht richtig.
The coffee machine has many functions, but it doesn't work properly.
The meaning of 'Funktion' (function) depends heavily on the subject area. In everyday language, it is about purpose (m01); in politics, about an office or role (m02); and in science and technology, about specific meanings in mathematics (m03) or computer science (m04).
Was ist die Funktion von diesem kleinen Hebel hier?
What is the function of this little lever here?
Common verbs used with 'Funktion' (function) in its general meaning are 'eine Funktion haben' (to have a function), 'eine Funktion erfüllen' (to fulfill a function), or 'außer Funktion sein' (to be out of order).
Der alte Aufzug ist seit gestern außer Funktion.
The old elevator has been out of order since yesterday.
The formal phrase 'in seiner/ihrer Funktion als ...' (in his/her function as ...) is used to emphasize the official role or office in which a person is acting or speaking.
Sie sprach nicht als Privatperson, sondern in ihrer Funktion als Geschäftsführerin.
She was not speaking as a private individual, but in her function as managing director.
The meanings in mathematics and computer science are purely technical language. They are used and understood only in these specific contexts.
Im Informatikunterricht lernen wir, wie man eine Funktion schreibt.
In computer science class, we're learning how to write a function.
role / roll
'die Rolle' and 'die Funktion' are close in meaning when talking about what someone or something is there for in a particular context. 'die Funktion' often sounds more factual and precise, especially with devices, things, systems, or official positions. 'die Rolle' is used more often when describing the importance or place of a person or thing in a situation. Learners may confuse the words because both can mean 'what something does'. As a guide: for technology and a clearly defined task, 'Funktion' works well; for people, groups, and contexts, 'Rolle' sounds more natural.

Vor dem Termin prüfen wir die Funktion des neuen Druckers.
Before the appointment, we check the function of the new printer.
Wegen ihrer Erfahrung hatte die Mitarbeiterin heute eine wichtige Rolle im Team.
Because of her experience, the employee had an important role in the team today.