在 Python 中打印“批准”标志/复选标记 (?) U+2713

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16676101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:20:58  来源:igfitidea点击:

Print the "approval" sign/check mark (?) U+2713 in Python

pythonunicode

提问by Mauro Aspé

How can I print the check mark sign "?" in Python?

如何打印复选标记“?” 在 Python 中?

It's the sign for approval, not a square root.

这是批准的标志,而不是平方根。

采纳答案by Jerome

You can print any Unicode character using an escape sequence. Make sure to make a Unicode string.

您可以使用转义序列打印任何 Unicode 字符。确保制作一个 Unicode 字符串。

print u'\u2713'

回答by lenz

Like this:

像这样:

print u'\u2713'.encode('utf8')

The encoding should match the one of your terminal (or wherever you are sending output to).

编码应该与您的终端之一(或您将输出发送到的任何地方)相匹配。

回答by pepper_chico

Solution defining python source file encoding:

定义python源文件编码的解决方案:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

print '?'

http://ideone.com/dTW5D8

http://ideone.com/dTW5D8

回答by Mr. Deathless

Since Python 2.1 you can use \N{name}escape sequence to insert Unicode characters by their names. Using this feature you can get check mark symbol like so:

从 Python 2.1 开始,您可以使用\N{name}转义序列按名称插入 Unicode 字符。使用此功能,您可以获得像这样的复选标记符号:

$ python -c "print(u'\N{check mark}')"
?

Note: For this feature to work you must use unicode string literal. uprefix is used for this reason. In Python 3 the prefix is not mandatory since string literals are unicode by default.

注意:要使用此功能,您必须使用 unicode 字符串文字。u为此使用前缀。在 Python 3 中,前缀不是强制性的,因为默认情况下字符串文字是 unicode。