+ 1

¿Alguien me puede explicar de qué sirve la i en estos codigos?(RESUELTO)

evens=[i**2 for i in range(10) if i**2 % 2 == 0] cubes = [i**3 for i in range(5)]

28th Oct 2023, 5:45 PM
Dorian Estévez
Dorian Estévez - avatar
5 Answers
+ 3
cubes = [i**3 for i in range(5)] this is an ordinary cycle written in ternary form. Similar code: cubes = [ ] for i in range(5): cubes[ i ] = i**3 evens = [i**2 for i in range(10) if i**2 % 2 == 0] This is the same, but with the addition of a condition for selecting even numbers raised to the second power. Similar code: evens = [ ] for i in range(10): if i**2 % 2 == 0]: evens[ i ] = i**2
28th Oct 2023, 5:55 PM
Solo
Solo - avatar
+ 2
Okay, thanks
28th Oct 2023, 6:13 PM
Dorian Estévez
Dorian Estévez - avatar
+ 1
Here it is customary to express gratitude as a like and a sign of the best answer.
28th Oct 2023, 6:36 PM
Solo
Solo - avatar
0
ok thanks, but then what does the i represent? a number or what?
28th Oct 2023, 6:05 PM
Dorian Estévez
Dorian Estévez - avatar
0
i this is the iterable number of the cycle range.
28th Oct 2023, 6:10 PM
Solo
Solo - avatar