In a Python program that I am writing, I need to print the © (copyright) symbol. Is there an easy way to do this? Or is it not supported in Python? Here's an example.
print ("\(copyright symbol here\)")
Just a very simple problem. Thanks!
In Python strings, the backslash "\" is a special character, also called the "escape" character. It is used in representing certain whitespace characters: "\t" is a tab, "\n" is a newline, and "\r" is a carriage return. Conversely, prefixing a special character with "\" turns it into an ordinary character.
Press Ctrl + Shift + u. Type in hexadecimal code for Unicode character you want to print. Press enter.
Use the repr() function to print a string with the special characters, e.g. print(repr(my_str)) . The repr() function returns a string containing a printable representation of the provided object. Copied! We used the repr() function to print a string with the special characters.
, \t, \r, etc., What if we want to print a string which contains these escape characters? We have to print the string using repr() inbuilt function. It prints the string precisely what we give.
The copyright sign is a unicode character. If your terminal supports a character encoding (such as utf-8 or cp1252) that includes this character, then you can print it:
This relies on Python detecting the terminal's character encoding:
In [64]: print(u'\N{COPYRIGHT SIGN}')
©
This uses an explicit encoding (which happens to work since my terminal is set to use the utf-8 character encoding):
In [65]: print(u'\N{COPYRIGHT SIGN}'.encode('utf-8'))
©
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With