[英]Why \ is used at the end of print statement in python?
Consider the code: 考虑代码:
firstName = raw_input("Your fist Name: ")
lastName = raw_input("Your last Name: ")
print "Hello %s, May I call you" \
"Mr. %s?" % (firstName,lastName)
In line 3, what is the use of \\
? 在第3行中,
\\
的用途是什么?
它允许您进行换行并在下一行继续您的语句
The \\
tells Python that the statement continues on the next line. \\
告诉Python该语句在下一行继续。 So, the print
statement doesn't end on the first line, it continues on the next. 因此,
print
语句不会在第一行结束,而在下一行继续。
print "Hello %s, May I call you" \
"Mr. %s?" % (firstName,lastName)
Is the same as: 是相同的:
print "Hello %s, May I call youMr. %s?" % (firstName,lastName)
The \\
character is used to break up long lines so they're easier to read and manage. \\
字符用于分隔长行,因此更易于阅读和管理。 The third and fourth lines could have been written as a single line without the \\
instead: 第三和第四行可以写为没有
\\
一行:
print "Hello %s, May I call youMr. %s?" % (firstName,lastName)
(note there is no space between "you" and "Mr." in the original post either) (请注意,原始帖子中的“您”和“先生”之间也没有空格)
使您能够将一行字符串溢出到多行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.