Fix NameError: name ‘xrange’ is not defined Error – Python Tutorial

By | September 25, 2019

In python 3, if you use xrange() function, you may find this error: NameError: name ‘xrange’ is not defined. In this tutorial, we will introduce how to fix this error in python 3.

NameError - name xrange is not defined

As code below in python 3:

for i in xrange(self.epoch):
            start = i*batch_size
            end = min((i+1)*batch_size, data_size)
                
            self.rank.append(np.asarray(self.t_rank[start:end]))

You should use range() function to replace xrange() funtion in python 3.

In python 3, xrange() is named as range(). You can not xrange() function again.

Leave a Reply