python - 如何打印格式指数
解决方案
怎么样:
def stringify_exponent(n, m):
superscripted = "".join(_DIGITS[int(d)] for d in str(m))
return f"{n}{superscripted}"
_DIGITS = [
"\N{superscript zero}",
"\N{superscript one}",
"\N{superscript two}",
"\N{superscript three}",
"\N{superscript four}",
"\N{superscript five}",
"\N{superscript six}",
"\N{superscript seven}",
"\N{superscript eight}",
"\N{superscript nine}"
]
if __name__ == "__main__":
print(stringify_exponent(10, 2))
print(stringify_exponent(2, 1024))
印刷:
10²
2¹⁰²⁴
推荐阅读
- c++ - C++,用n个元素替换第i个元素(低复杂度)
- php - if else 循环使用 div 为 post count 0 和 >0
- c++ - MSVS C++ 2012:如何禁用编译时编辑
- mysql - 在mySql中计算具有不同条件的表中的元素?
- javascript - 使用 ExtractTextPlugin 的 SASS 到 CSS
- java - 在 Intellij IDEA 中安装 Java Card Development Kit
- reactjs - 在加载新状态之前对渲染消息做出反应
- ios - iTunes Connect Test Flight 上不显示构建版本
- css - CSS网格等大小列
- system.reactive - 为什么/我应该在没有 Connect 的情况下使用 Publish?