推荐学习书目
› 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
Kakarrot
V2EX  ›  Python

Python 字符串拼接

  •  
  •   Kakarrot · Nov 29, 2018 · 2529 views
    This topic created in 2858 days ago, the information mentioned may be changed or developed.
    dir = "192.168.10.245\cloud"
    
    file = "b9/e1/eb/b9e1eb55-3524-4337-93c0-1b5c3c01c6f8.png"
    

    怎么拼接成"\192.168.10.245\cloud\b9/e1/eb/b9e1eb55-3524-4337-93c0-1b5c3c01c6f8.png"

    4 replies  •  2018-12-01 21:11:13 +08:00
    ech0x
        1
    ech0x  
       Nov 29, 2018
    c = "{}\{}".format(dir,file)
    ech0x
        2
    ech0x  
       Nov 29, 2018
    漏看量一个反斜杠。
    应该是
    c = "\{}\{}".format(dir,file)
    jxie0755
        3
    jxie0755  
       Nov 30, 2018
    直接用+号拼接不就行了吗........
    speedbird
        4
    speedbird  
       Dec 1, 2018
    ```python
    dir = "192.168.10.245\cloud"

    file = "b9/e1/eb/b9e1eb55-3524-4337-93c0-1b5c3c01c6f8.png"

    string = f'\{dir}\{file}'
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2678 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 14:57 · PVG 22:57 · LAX 07:57 · JFK 10:57
    ♥ Do have faith in what you're doing.