[英]Is there a way to write an exponent in a string using python? Not just ^2
I'm just starting to learn python.我刚刚开始学习 python。 When I ask for input from the user, can I write an exponent within that?
当我要求用户输入时,我可以在其中写一个指数吗? Can I do that aside from "^2"?
除了“^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:我的 output 将是:
Gravity (in m/s^2, 9.8 for Earth, 24 for Jupiter):
But I want the "2" to look like an actual exponent.但我希望“2”看起来像一个实际的指数。 Is that possible?
那可能吗?
Text strings are unicode in Python, you can use the character SUPERSCRIPT TWO directly in a string:文本字符串为 Python 中的 unicode,可以在字符串中直接使用字符SUPERSCRIPT TWO :
float(input(f"Gravity in m/s², 9.8 for Earth, 24 for Jupiter): "))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.