我这次没有写文档翻译错误,表示英文原文表达的意思和程序命令实际执行效果之间也有差异。
先看测试代码:
b="""
Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
"""
print('b变量是默认输出:')
print(b)
for i in b:
if ord(i) == 10:
print('有换行符')
再看原来的英文,怎么说明这个执行效果的:
End of lines are automatically included in the string, but it’s possible to prevent this by adding a \ at the end of the line.
没有把程序执行的效果说完整。
首先,漏了增加的字符串开头换行符。
其实,后面半句说可以用\字符来prevent增加的换行符。这个是没有错,但是下面举的例子,其实不是在the end of the line插入\,恰恰是文档里没有说到的the start of the multiple lines。这样写文档和例子,读者会感觉到有点奇怪的。
The text was updated successfully, but these errors were encountered:
我这次没有写文档翻译错误,表示英文原文表达的意思和程序命令实际执行效果之间也有差异。
先看测试代码:
b="""
Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
"""
print('b变量是默认输出:')
print(b)
for i in b:
if ord(i) == 10:
print('有换行符')
print('b变量的长度是',len(b))
print('b变量第一个字符的ASCii是',ord(b[0]))
print('b变量最后一个字符的ASCii是',ord(b[-1]))
a ="""
Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
"""
print()
print('a变量是插入4个\字符后输出:')
print(a)
print('a变量的长度是',len(a))
print('a变量第一个字符的ASCii是',ord(a[0]), '字符:'+a[0])
print('a变量最后一个字符的ASCii是',ord(a[-1]), '字符:'+a[-1])
执行结果:
b变量是默认输出:
Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
有换行符
有换行符
有换行符
有换行符
b变量的长度是 137
b变量第一个字符的ASCii是 10
b变量最后一个字符的ASCii是 10
a变量是插入4个\字符后输出:
Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to
a变量的长度是 133
a变量第一个字符的ASCii是 85 字符:U
a变量最后一个字符的ASCii是 111 字符:o
总结:
python默认给每个多行字符串里,增加了行数n+1个换行符,例子里是3行,所以是4个:其中开头一个,每行末尾一个。如果要取消加的4个换行符,那么在相应位置插入\字符。
再看原来的英文,怎么说明这个执行效果的:
End of lines are automatically included in the string, but it’s possible to prevent this by adding a \ at the end of the line.
没有把程序执行的效果说完整。
首先,漏了增加的字符串开头换行符。
其实,后面半句说可以用\字符来prevent增加的换行符。这个是没有错,但是下面举的例子,其实不是在the end of the line插入\,恰恰是文档里没有说到的the start of the multiple lines。这样写文档和例子,读者会感觉到有点奇怪的。
The text was updated successfully, but these errors were encountered: