Search code examples
pythonpython-3.xstringunicodepython-unicode

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))

Solution

  • 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 𝚮