Python for statement variable declaration

Asked 2 years ago, Updated 2 years ago, 123 views

I want to declare a variable in the for statement in Python and receive a value, so what should I do?

for i in range(10):
value_i = i



print(value_4)

python variable

2022-09-22 18:27

1 Answers

Create an empty array outside of for and insert the necessary values in order.

values = []
for i in range(10) :
  values[i] = i*3
print(values[4]) # 12


2022-09-22 18:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.