xrange与itertools.count Python 2.7 [英] xrange versus itertools.count Python 2.7
本文介绍了xrange与itertools.count Python 2.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想运行一个从开始到结束值的范围.它在较小的数字上工作正常,但是当数字太大时会导致溢出错误,因为int太大而无法转换为C Long.我正在使用Python 2.7.3.
I want to run a range from a start to an end value. It works fine on low numbers but when it gets too large it causes an overflow error as int too large to convert to C Long. I am using Python 2.7.3.
我在这里阅读 OverflowError Python int太大,无法使用itertools.count()
方法转换为C long ,只是该方法的作用与xrange
方法不同,因为通过步进而不是声明结束范围值.
I read here OverflowError Python int too large to convert to C long on using the itertools.count()
method except that method works differently to the xrange
method by stepping as opposed to declaring an end range value.
可以将itertools.count()
设置为像xrange()
一样工作吗?
Can the itertools.count()
be set up to work like xrange()
?
print "Range start value"
start_value = raw_input('> ')
start_value = int(start_value)
print "Range end value"
end_value = raw_input('> ')
end_value = int(end_value)
for i in xrange(start_value, end_value):
print hex(i)
推荐答案
查看全文