IndexError: list index of range. Python 3
<p>I was just trying to create a Matrix filled with zeros, like the function of numpy.</p>

<p>But it continues to give me that error. Here's the code:</p>

<pre><code>def zeros(a,b):

     for i in range(a):
        for j in range(b):  
            R[i][j]=0
      return R
</code></pre>

<p>I tried with a=3 and b=2, so it would give me a 3x2 matrix filled with zeros. It is a part of the program to multiply matrix</p>

<p>I'm new in this whole programming world, thanks for the help.</p>

<p>You could do that:</p>

<pre><code>&gt;&gt;&gt; def zeros(a,b):
...     return [[0 for _ in range(a)] for _ in range(b)]
...
&gt;&gt;&gt; zeros(3,2)
[[0, 0, 0], [0, 0, 0]]
</code></pre>

<p>Or something more close to your code:</p>

<pre><code>def zeros(a,b):
    R = []
    l = [0]*a
    for _ in range(b):
        R.append(l)
    return R
</code></pre>

python python-3.x