如何在Ipython输出中获取换行符 [英] How do I get a newline in a Ipython output

查看:240
本文介绍了如何在Ipython输出中获取换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑IPython笔记本中的以下输入:

Consider the following input in a IPython notebook:

mu = 39.95   
Z=1
Latex(r"Atomic Mass: $\quad \mu$= %0.5e Hz" %(mu))
Latex(r"Charge state: $\quad z$= %0.5e" %(Z))

我的问题分为两部分。

(A)缺少输出

从上面来源,令人惊讶的是我得到了以下结果:

From above source, Surprisingly I got the following result:

 Charge state:  z = 1.00000e+00

第一行发生了什么(即没有打印$ mu $的值)?

What happened to the first line (i.e the value of $mu$ was not printed)?

(B)缺少换行符

然而,我可以使用以下内容获得结果:

I was however able to get the result using the following:

      Latex(r"Atomic Mass: $\quad \mu$= %0.5e Hz   " %(mu) + r"Charge state: $\quad z$= %0.5e" %(Z))

但是现在,我需要上面的换行符。怎么做呢?

But now, I need a newline in the above. How does one do it?

推荐答案

默认情况下,笔记本只渲染单元格中获得的最后一个值。使用 IPython.display.display 作为增强的 print 函数来显示以下内容:

By default the notebook only renders the last value obtained in a cell. Use IPython.display.display as an augmented print function to display several things:

from IPython.display import Latex, display

mu = 39.95   
Z=1
display(Latex(r"Atomic Mass: $\quad \mu$= %0.5e Hz" % mu))
display(Latex(r"Charge state: $\quad z$= %0.5e" % Z))

这篇关于如何在Ipython输出中获取换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆