简体   繁体   English

有没有办法使用 python 在字符串中写入指数? 不只是^2

[英]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.

相关问题 需要写一个带有指数的字符串到文件 - Need to write a string with exponent to file 在Python中解析表示带*浮点数的字符串 - Parsing a string representing a float *with an exponent* in Python Python:以字符串形式显示的指数字符 - Python: Exponent-Characters shown in string 我有一个 RSA 公钥指数和模数。 如何使用 Python 加密字符串? - I have a RSA public key exponent and modulus. How can I encrypt a string using Python? Python 如何使用模数 + 指数使用 RSA 进行编码 - Python how to encode with RSA using modulus + exponent 有没有一种方法可以在不使用循环和列表理解的情况下在 python 中获取字符串的排列 - 只是递归 - Is there a way of getting the permutations of a string without using loops and list comprehension in python - Just recursion 在Python中创建文件并向其中写入字符串的最简单方法 - Simplest way to create a file and write a string to it in Python 如何在 python 中将 E 表示法字符串转换为具有固定指数的浮点数 - How to convert a E notation string to a float with fixed exponent in python 有没有一种使用 Python 编写 ODT 的简单方法? - Is there a simple way to write an ODT using Python? 在Python中使用带浮点值的指数运算符(**)时出现意外输出 - Unexpected output when using exponent operator(**) with float value in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM