Print the "approval" sign/check mark (✓) U+2713 in Python
Question:
How can I print the check mark sign “✓” in Python?
It’s the sign for approval, not a square root.
Answers:
You can print any Unicode character using an escape sequence. Make sure to make a Unicode string.
print u'u2713'
Like this:
print u'u2713'.encode('utf8')
The encoding should match the one of your terminal (or wherever you are sending output to).
Solution defining python source file encoding:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
print '✓'
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 -c "print(u'N{check mark}')"
✓
Note: For this feature to work you must use unicode string literal. u
prefix is used for this reason. In Python 3 the prefix is not mandatory since string literals are unicode by default.
How can I print the check mark sign “✓” in Python?
It’s the sign for approval, not a square root.
You can print any Unicode character using an escape sequence. Make sure to make a Unicode string.
print u'u2713'
Like this:
print u'u2713'.encode('utf8')
The encoding should match the one of your terminal (or wherever you are sending output to).
Solution defining python source file encoding:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
print '✓'
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 -c "print(u'N{check mark}')"
✓
Note: For this feature to work you must use unicode string literal. u
prefix is used for this reason. In Python 3 the prefix is not mandatory since string literals are unicode by default.