V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 2263 views
    This topic created in 2716 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   ·   Solana   ·   3231 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 00:20 · PVG 08:20 · LAX 17:20 · JFK 20:20
    ♥ Do have faith in what you're doing.