社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

v.tralala

v.tralala 最近创建的主题
v.tralala 最近回复了
5 年前
回复了 v.tralala 创建的主题 » python:无法格式化类似json的字符串[duplicate]

我在尝试打印文本时偶然发现了这个问题,我可以将其复制粘贴到乳胶文档中。我继续 this answer 并使用命名替换字段:

假设您要打印多个变量的乘积,这些变量的索引如下 enter image description here ,在乳胶中 $A_{ 0042 }*A_{ 3141 }*A_{ 2718 }*A_{ 0042 }$

idx_mapping = {'i1':42, 'i2':3141, 'i3':2178 }
print('$A_{{ {i1:04d} }} * A_{{ {i2:04d} }} * A_{{ {i3:04d} }} * A_{{ {i1:04d} }}$'.format(**idx_mapping))