zoukankan      html  css  js  c++  java
  • Python中range()和xrange()的区别?

    range()方法返回一个list列表,一次性生成。

    xrange()方法返回的是一个xrange()对象。

    我所知道的只是xrange()方法更省内存。

    Xrange()方法的官方定义:
    xrange(start, stop[, step]) This function
    is very similar to range(), but returns an xrange object instead of a list.
    This is an opaque sequence type which yields the same values as the corresponding list, without actually storing them all simultaneously.
    The advantage of xrange() over range() is minimal (since xrange() still has to create the values when asked for them) except
    when a very large range is used on a memory-starved machine or when all of the range’s elements are never used (such as when the loop is usually terminated with break).
    For more information on xrange objects, see XRange Type and Sequence Types — str, unicode, list, tuple, bytearray, buffer, xrange.
  • 相关阅读:
    codeforces round#600
    第三章:数据操作
    1143 Lowest Common Ancestor (30 分)
    游标
    1151 LCA in a Binary Tree (30 分)
    jQuery之setInterval()定时器
    C程序第四次作业
    C程序第三次作业
    C程序第二次作业
    C程序第一次作业
  • 原文地址:https://www.cnblogs.com/ZT-SummerRain/p/7494472.html
Copyright © 2011-2022 走看看