V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
yakczh
V2EX  ›  Python

python 的 list 和 dict 跟 js 的 Array Object 语法竟然一样

  •  
  •   yakczh · 2014 年 5 月 18 日 · 4392 次点击
    这是一个创建于 4262 天前的主题,其中的信息可能已经有所发展或是发生改变。
    学一门就相当于会两门,这不是赚大发了吗?
    4 条回复
    pacino
        1
    pacino  
       2014 年 5 月 18 日
    恭喜你~
    unionx
        2
    unionx  
       2014 年 5 月 18 日
    不一样哦
    est
        3
    est  
       2014 年 5 月 18 日
    a = {None: u'haha'}
    bravluna
        4
    bravluna  
       2014 年 5 月 18 日
    这是你的重大发现吗?
    1,list 不能是稀疏的,且不能超出索引赋值,增长只能用『+』或 append();array 可以是稀疏的,可以给任意索引赋值
    2,dict 的键可以是个不可变的对象,比如 {(None,): 1},Object 的键只有一种:字符串
    3,JS 里 array 其实就是个 Object 哦,var ary = [1, 2, 3]; ary["1"] = null; 于是 ary 变成了 [1, null, 3]
    结论:不一样的地方比一样的地方更多!
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2401 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 01:14 · PVG 09:14 · LAX 17:14 · JFK 20:14
    ♥ Do have faith in what you're doing.