R
R
Robert2021-07-06 20:50:21
Python
Robert, 2021-07-06 20:50:21

How to add a symbol to the name of a variable?

I have this piece of code

temp1 = str(res["daily"][0]["temp"]["day"])
    temp2 = str(res["daily"][1]["temp"]["day"])
    temp3 = str(res["daily"][2]["temp"]["day"])
    temp4 = str(res["daily"][3]["temp"]["day"])
    temp5 = str(res["daily"][4]["temp"]["day"])
    temp6 = str(res["daily"][5]["temp"]["day"])
    temp7 = str(res["daily"][6]["temp"]["day"])
    temp8 = str(res["daily"][7]["temp"]["day"])


and 4 more pieces of similar code.
I would like to do it through a loop, but the "Problem" is that different variable names are needed.
How to change the number in the variable itself, I know, but how to add some number to the name without a clue... Please help...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ronald McDonald, 2021-07-06
@Lerts

4 pieces of similar code.

What a clear feature.
Answer: replace a bunch of variables with an array and process it with a loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question