Creating histos trough for loop (PyROOT)

I am trying to get a feel for pyRoot and have a basic beginner question:
How do I create Histograms trough a loop?

I’ve got this code which should create two identical histograms and save them to a root file. I know the code is wrong and it does not quite make sense to me neither but you should get the idea of what I am trying to do:

import ROOT as root
from ROOT import gROOT, TCanvas, TF1, TH1, TFile

f = root.TFile("demo.root", "RECREATE")

c1 = root.TCanvas()

for i in range(2):

	h[i] = root.TH1D("h" + str(i), "Histogram" + str(i), 10, 0, 10)

	for _ in range(1000):
		g = root.gRandom.Gaus(5,2)
		h[i].Fill(g)
		

	h[i].Draw()

c1.Update()

f.Write()

Appreciate the help.

Hello,

In order to make the code work, try to write h = [] before the for loop. Then, instead of

h[i] = ...

use

h.append(...)

Cheers,
Jakob