简体   繁体   中英

Print Greek letter in printed string

How do i get this to print the eta symbol please?? At the moment it just returns $\eta$ as opposed to the actual letter.

print(r'The conversion factor from z to $\eta$ is %a' %round(n,4))

There are a number of eta characters . You can print them using their names from the unicode standard:

import unicodedata as ud

>>> for eta in etas:
...     print(eta, ud.lookup(eta))
... 
GREEK CAPITAL LETTER ETA Η
GREEK SMALL LETTER ETA η
GREEK CAPITAL LETTER ETA Η
GREEK SMALL LETTER ETA η
MATHEMATICAL BOLD CAPITAL ETA 𝚮
MATHEMATICAL BOLD SMALL ETA 𝛈
MATHEMATICAL ITALIC CAPITAL ETA 𝛨
MATHEMATICAL ITALIC SMALL ETA 𝜂
MATHEMATICAL BOLD ITALIC CAPITAL ETA 𝜢
MATHEMATICAL BOLD ITALIC SMALL ETA 𝜼

Or by escaping their names like this: \\N{NAME} :

>>> print('\N{GREEK CAPITAL LETTER ETA}')
Η

Or using unicode hex escape sequences, like this:

>>> print('GREEK CAPITAL LETTER ETA \u0397')
GREEK CAPITAL LETTER ETA Η

>>> print('GREEK MATHEMATICAL BOLD CAPITAL ETA \U0001d6ae')
GREEK MATHEMATICAL BOLD CAPITAL ETA 𝚮

This website provides some helpful suggestions: https://pythonforundergradengineers.com/unicode-characters-in-python.html

>>> print('Omega: \u03A9')
Omega: Ω
>>> print('Delta: \u0394')
Delta: Δ
>>> print('sigma: \u03C3')
sigma: σ
>>> print('mu: \u03BC')
mu: μ
>>> print('epsilon: \u03B5')
epsilon: ε
>>> print('degree: \u00B0')
degree: °
>>> print('6i\u0302 + 4j\u0302-2k\u0302')
6î + 4ĵ-2k̂

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM