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-05-18 13:25:04 +08:00 · 3897 次点击
    这是一个创建于 3636 天前的主题,其中的信息可能已经有所发展或是发生改变。
    学一门就相当于会两门,这不是赚大发了吗?
    4 条回复
    pacino
        1
    pacino  
       2014-05-18 13:55:24 +08:00
    恭喜你~
    unionx
        2
    unionx  
       2014-05-18 15:03:20 +08:00
    不一样哦
    est
        3
    est  
       2014-05-18 15:20:17 +08:00
    a = {None: u'haha'}
    bravluna
        4
    bravluna  
       2014-05-18 17:28:26 +08:00
    这是你的重大发现吗?
    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   ·   我们的愿景   ·   实用小工具   ·   2259 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 03:00 · PVG 11:00 · LAX 20:00 · JFK 23:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.