python - 拆分字符串行代码而不拆分其输出
问题描述
我正在使用 Python 3.7.7。
我有这个代码:
print("Shape:{} - N-Way:{} - Num-shot:{} - Num-query:{} - Epochs:{} - \
Episodes:{} - Loss_function:'{}' - Accuracy:'{}'".format(image_shape,
num_way, num_shot, num_query, num_epochs, num_episodes, loss_name,
accuracy_name))
我Epochs:{} - \
用来避免行超过 80 个字符。但我得到这个输出:
Shape:(200, 200, 1) - N-Way:2 - Num-shot:5 - Num-query:5 - Epochs:2 - Episodes:10 - Loss_function:'dice_coef_loss' - Accuracy:'accuracy'
和Epochs:2 - Episodes:10 -
之间有这个空间。Epochs
Episodes
有没有办法避免呢?我要这个:Epochs:2 - Episodes:10 -
解决方案
你可以这样做:
print("Shape:{} - N-Way:{} - Num-shot:{} - Num-query:{} - Epochs:{} - "
"Episodes:{} - Loss_function:'{}' - Accuracy:'{}'"
.format(image_shape, num_way, num_shot, num_query, num_epochs,
num_episodes, loss_name, accuracy_name))
它之所以有效,是因为在 Python 中,如果您有两个仅由空格分隔的字符串文字,则它等效于仅连接这些文字:
>>> 'asd' 'fgh'
'asdfgh'
推荐阅读
- python - rtype 在 Python 中是什么意思?
- fullcalendar - FullCalendar - 垂直时间线,水平天数
- class - Java 8 检查扩展另一个对象的对象的类或实例
- websocket - 根据有效负载从效果中切换最终发出的动作
- java - 嵌套地图上的流
- jquery - 数据表中的自定义过滤器地址和日期范围
- javascript - 更改用户 Firebase 身份验证时触发的事件
- arrays - Xcode Time Profiler 的详细信息面板显示“main”是应用程序运行缓慢的原因,但没有在其中显示单独的方法调用。
- java - 为什么下面的按位运算会产生数值溢出?
- c# - 在 .net core 2.0 中注册多个服务