a=0
b=1
c=2
d=3
e=4
Var = [a,b,c,d,e]
Var2 =[]
for i in Var:
if i <= 2:
Var2 = [i]
print(Var2)
this is the result
[2]
Process finished with exit code 0
CodePudding user response:
Replcae Var2 = [i]
with:
Var2 = [i]
or you can use Var2.append(i)
CodePudding user response:
Use append() function of list.
for i in Var:
if i <= 2:
Var2.append(i)
print(Var2)