Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to write an exponent in a string using python? Not just ^2

I’m just starting to learn python. When I ask for input from the user, can I write an exponent within that? Can I do that aside from "^2"?

Let’s say this is my code:

float(input("Gravity in m/s^2, 9.8 for Earth, 24 for Jupiter): "))

My output would be:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Gravity (in m/s^2, 9.8 for Earth, 24 for Jupiter):

But I want the "2" to look like an actual exponent. Is that possible?

>Solution :

Text strings are unicode in Python, you can use the character SUPERSCRIPT TWO directly in a string:

float(input(f"Gravity in m/s², 9.8 for Earth, 24 for Jupiter): "))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading