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

标签 python windows python-2.7 console control-characters

当我尝试打印\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/

相关文章:

Python 退出处理程序

windows - 没有 Windows 窗体的 AddMessageFilter?

c# - 从 uwp 应用程序中的代码打开表情符号面板

python - 防止 python 加载 pth 文件

python - 为什么 '[0-9]*' 与我的 Python 正则表达式中的 'abc' 不匹配,因为字符串中有零个或多个数字?

python - 用于拉伸(stretch)/压缩音频文件以在 python 中具有预设数量的样本的功能?

python - django-rest-framework "AttributeError: ' 函数'对象没有属性 'get_extra_actions' ”

python - 如何使用 xml.etree.ElementTree 将 "standalone="yes"添加到 XML 声明

windows - cmd.exe 命令行中必须转义哪些符号?

python-2.7 - 在 spark 环境中运行 python 程序时出错