Problem Formulation
- Given two strings x and y.
- Create a new string xy and print it to the shell.
Consider the following examples:
INPUT x = 'hi' y = 'finxter' OUTPUT: hifinxter INPUT x = '2' y = '4' OUTPUT: 24 INPUT x = 'abc' y = '[1, 2, 3]' OUTPUT: abc[1, 2, 3]
Solution for Jupyter Notebooks
A simple approach is given here:
from IPython.display import display, Math display(Math('hello^{finxter}'))
A general approach is given here—simply replace x
and y
with your own variables:
from IPython.display import display, Math x = 'hello' y = 'finxter' display(Math(x + '^{' + y + '}'))
You can try it yourself here:
For Python, it doesn’t work in a general way. The reason is that Unicode doesn’t provide a way to superscript general code. An idea for further investigation would be to use a Latex library that allows you to write and display Latex code within Python.

While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.