+ 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)]
5 odpowiedzi
+ 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
+ 2
Okay, thanks
+ 1
Here it is customary to express gratitude as a like and a sign of the best answer.
0
ok thanks, but then what does the i represent? a number or what?
0
i this is the iterable number of the cycle range.