What is the purpose of a backslash at the end of a line?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-28 01:36:42

问题


Just found the following module import in a Python code:

from sqlalchemy.ext.declarative import declarative_base,\
      AbstractConcreteBase

I am curious about the backslash \ at the end of the first line. What's the purpose of it? Wouldn't it be the same as the following?

from sqlalchemy.ext.declarative import declarative_base, AbstractConcreteBase

回答1:


Yep, it's exactly the same and this is the point of the backslash — it escapes the newline, allowing this long line to be split in two. An alternative is to use parentheses:

from sqlalchemy.ext.declarative import (declarative_base,
      AbstractConcreteBase)

While this is a syntax error:

from sqlalchemy.ext.declarative import declarative_base,
      AbstractConcreteBase


来源:https://stackoverflow.com/questions/16060238/what-is-the-purpose-of-a-backslash-at-the-end-of-a-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!