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
xylsmmmmmmmm3
V2EX  ›  Python

用 str 转成字符串和 join 转成字符串有什么区别?

  •  
  •   xylsmmmmmmmm3 · 2017-09-14 17:38:32 +08:00 · 2899 次点击
    这是一个创建于 2387 天前的主题,其中的信息可能已经有所发展或是发生改变。
    4 条回复    2017-09-15 11:39:06 +08:00
    petelin
        1
    petelin  
       2017-09-14 19:35:21 +08:00
    a['a'] 是个列表, str 的时候,就是那么打印的

    ''.join(a['a']) .........

    算了我懒得吐槽了..... 两个方法都不一样. 为什么你会认为输出一定要一样?
    aixia0124
        2
    aixia0124  
       2017-09-14 20:05:22 +08:00 via iPhone
    不是一个东西,还有为什么用 a['a']这种怪异的动作。

    如果你把字符串当成一个对象,那 join 就是这个对象的一个方法,好像接收的参数是一个可迭代对象。

    str 是不同的函数
    aaronzjw
        3
    aaronzjw  
       2017-09-14 23:40:50 +08:00
    str(a['a']) 不懂对列表用 str 什么意思
    flyingghost
        4
    flyingghost  
       2017-09-15 11:39:06 +08:00
    先看书,再提问。
    你这问题本身就不及格。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3218 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:38 · PVG 19:38 · LAX 04:38 · JFK 07:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.