gpt4 book ai didi

python - 使用转义序列时的错误符号 很难学习 python ex10

转载 作者:可可西里 更新时间:2023-11-01 11:18:13 25 4
gpt4 key购买 nike

当我尝试打印\v 或\f 时,我得到的是性别符号:

screenshot

另请注意,我完全是编程初学者。

编辑:好像我写的不够清楚,我不想想写\v或\f但是他们创建的转义序列,我不知道他们到底做了什么但我不认为这个是他们的预期功能-

最佳答案

您正在尝试打印特殊字符,例如 "\n"== new line。您可以在此处了解更多信息:Python String Literals .

摘录:

In plain English: String literals can be enclosed in matching single quotes (') or double quotes ("). They can also be enclosed in matching groups of three single or double quotes (these are generally referred to as triple-quoted strings). The backslash (\) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character. String literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and use different rules for interpreting backslash escape sequences.

r 告诉它打印“原始字符串”。

Python 2.7ish:

print r"\v"

或者,您可以转义转义字符:

print "\\v"

或者,对于动态打印:

print "%r" % ("\v",)

关于python - 使用转义序列时的错误符号 很难学习 python ex10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27680866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com