V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ropon
V2EX  ›  问与答

请求 Python 相关的小知识点

  •  
  •   ropon · Nov 23, 2018 · 1097 views
    This topic created in 2724 days ago, the information mentioned may be changed or developed.

    a = [1, 2] print('列表 a 的内存地址:{0}'.format(id(a))) print('元素 a[0]的内存地址:{0}'.format(id(a[0]))) print('元素 a[1]的内存地址:{0}'.format(id(a[1])))

    a[1]=a

    print('赋值后列表 a 的内存地址:{0}'.format(id(a))) print('赋值后元素 a[0]的内存地址:{0}'.format(id(a[0]))) print('赋值后元素 a[1]的内存地址:{0}'.format(id(a[1])))

    print(a[1])

    列表 a 的内存地址:3068631745480 元素 a[0]的内存地址:1531210496 元素 a[1]的内存地址:1531210528 赋值后列表 a 的内存地址:3068631745480 赋值后元素 a[0]的内存地址:1531210496 赋值后元素 a[1]的内存地址:3068631745480 [1, [...]]

    请问怎么理解呢? [...] 是怎么来的呢?

    1 replies    2018-11-23 12:22:50 +08:00
    ClutchBear
        1
    ClutchBear  
       Nov 23, 2018
    a[1]=a
    这一句导致无穷嵌套
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5390 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 08:06 · PVG 16:06 · LAX 01:06 · JFK 04:06
    ♥ Do have faith in what you're doing.