Notes
for loop over a function
Content of the notes (1)
Page 1
for loop over a function
For Loop Over a Function
A for loop can also be used to execute a function multiple times. For example, below we are executing celsius_to_kelvin three times since there are three items in the iterating list:
def celsius_to_kelvin(cels):
return cels + 273.15
for temperature in [9.1, 8.8, -270.15]:
print(celsius_to_kelvin(temperature))
The output of that would be:
282.25
281.95
3.0
So, in the first iteration celsius_to_kelvin(9.1) was executed, in the second celsius_to_kelvin(8.8) and in the third celsius_to_kelvin(-270.15).
Contenido del curso
Contenido del curso
Descripción general
Notas
Anuncios
Valoraciones
Herramientas de aprendizaje
Information
- Description
- Note on for loop over a function, created by Sofia Sarachu on 29/10/2024.
- Created by
- Sofia Sarachu
- Views
- 0
- Rating