行尾反斜杠的目的是什么? [英] What is the purpose of a backslash at the end of a line?
本文介绍了行尾反斜杠的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
刚刚在 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)
虽然这是一个语法错误:
While this is a syntax error:
from sqlalchemy.ext.declarative import declarative_base,
AbstractConcreteBase
这篇关于行尾反斜杠的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文