打印和显示之间的区别
提供打印的理由 是显示和写入两者 有比较标准的输出 惯例和这种标准化 限制环境的方式 可以改变这些人的行为 程序。 无输出约定 应假设用于打印,以便 环境可以自由修改 print in 生成的实际输出 无论如何。
有人可以解释一下这对于菜鸟来说意味着什么以及打印和显示有何不同吗?
PLT Scheme's documentation says:
The rationale for providing print
is that display and write both
have relatively standard output
conventions, and this standardization
restricts the ways that an environment
can change the behavior of these
procedures. No output conventions
should be assumed for print, so that
environments are free to modify the
actual output generated by print in
any way.
Could somebody please explain what that means for a noob and how is print and display different?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题是程序可以从
write
和display
获得某些输出格式。 在 PLT 中,可以改变它们的行为方式,但这样做需要一点参与。 这是有意为之的,因为进行这样的改变可能会产生戏剧性的、意想不到的结果。OTOH,改变
print
的行为方式非常简单——只需查看current-print
文档即可。 这个想法是,print
用于调试,用于在交互式 REPL 中向您呈现代码 - 而不是作为您将依赖的输出的工具,需要以特定方式格式化。 (顺便说一句,另请参阅format
、printf
等的“~v”指令)The thing is that programs can expect certain output formats from
write
anddisplay
. In PLT, it is possible to change how they behave, but a little involved to do so. This is intentional, since doing such a change can have dramatic and unexpected result.OTOH, changing how
print
behaves is deliberately easy -- just see thecurrent-print
documentation. The idea is thatprint
is used for debugging, for presenting code to you in an interactive REPL -- not as a tool that you will rely on for output that needs to be formatted in a specific way. (BTW, see also the "~v" directive forformat
,printf
, etc.)您可以自由覆盖打印功能。 如果您想要覆盖标准化函数,例如write,您必须遵守输出标准,否则使用它的代码可能会崩溃。
关于显示和写入:
TheScheme编程语言,第3版,第1页。 178
You are free to override print function. If you want to override standardized functions, for example the write, you must obey to the output standard, otherwise code that use it will possibly break.
About display and write:
The Scheme Programming Language, 3rd edition, pg. 178
如果您不想替换 print,您可以尝试 SRFI-28:
http://srfi.schemers.org/srfi-28/srfi-28.html
If you don't want to replace print you might try out SRFI-28 instead:
http://srfi.schemers.org/srfi-28/srfi-28.html
在Python中,print()函数主要用于调试和在控制台中显示简单的文本输出。 它可用于显示变量的值、向用户打印消息或记录有关程序执行的信息。 print() 的输出通常是无格式的并且缺乏视觉吸引力。
另一方面,display() 函数通常用于数据分析和可视化,以更有条理、更美观的格式显示数据。 它通常在 Jupyter 笔记本和其他交互式环境中用于显示数据框、绘图、图表和其他类型的图形表示。 display() 函数还可用于格式化和风格化数据框或其他数据结构的输出。
总而言之, print() 主要用于调试和显示简单的文本输出,而 display() 用于以更有组织性和视觉吸引力的格式显示数据,特别是在数据分析和可视化上下文中。
前任:
打印(数据框)
在此处输入图像描述
display(dataframe)
在此处输入图片说明
In Python, the print() function is primarily used for debugging and displaying simple text output in the console. It can be used to display the value of a variable, print a message to the user, or log information about the program's execution. The output of print() is often unformatted and lacks visual appeal.
On the other hand, the display() function is typically used in data analysis and visualization to display data in a more organized and aesthetically pleasing format. It is often used in Jupyter notebooks and other interactive environments to show data frames, plots, charts, and other types of graphical representations. The display() function can also be used to format and stylize the output of a data frame or other data structure.
To summarize, print() is primarily used for debugging and displaying simple text output, while display() is used for displaying data in a more organized and visually appealing format, particularly in data analysis and visualization contexts.
ex:
print(dataframe)
enter image description here
display(dataframe)
enter image description here