ropon
V2EX  ›  问与答

请求 Python 相关的小知识点

  •  
  •   ropon · Nov 23, 2018 · 1138 views
    This topic created in 2752 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   ·   1215 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 17:49 · PVG 01:49 · LAX 10:49 · JFK 13:49
    ♥ Do have faith in what you're doing.