在一行结尾处反斜杠的目的是什么? [英] What is the purpose of a backslash at the end of a line?

查看:265
本文介绍了在一行结尾处反斜杠的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚在Python代码中找到以下模块导入:

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


推荐答案

是的,它完全相同,这是反斜杠的重点 - 它逃脱换行符,允许将这条长行分成两行。另一种方法是使用括号:

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)

虽然这是语法错误:

from sqlalchemy.ext.declarative import declarative_base,
      AbstractConcreteBase

这篇关于在一行结尾处反斜杠的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆