打印和显示之间的区别

发布于 2024-07-22 10:00:25 字数 477 浏览 3 评论 0原文

PLT 方案文档 说:

提供打印的理由显示写入两者 有比较标准的输出 惯例和这种标准化 限制环境的方式 可以改变这些人的行为 程序。 无输出约定 应假设用于打印,以便 环境可以自由修改 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

简美 2024-07-29 10:00:25

问题是程序可以从 writedisplay 获得某些输出格式。 在 PLT 中,可以改变它们的行为方式,但这样做需要一点参与。 这是有意为之的,因为进行这样的改变可能会产生戏剧性的、意想不到的结果。

OTOH,改变 print 的行为方式非常简单——只需查看 current-print 文档即可。 这个想法是,print 用于调试,用于在交互式 REPL 中向您呈现代码 - 而不是作为您将依赖的输出的工具,需要以特定方式格式化。 (顺便说一句,另请参阅 formatprintf 等的“~v”指令)

The thing is that programs can expect certain output formats from write and display. 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 the current-print documentation. The idea is that print 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 for format, printf, etc.)

说好的呢 2024-07-29 10:00:25

您可以自由覆盖打印功能。 如果您想要覆盖标准化函数,例如write,您必须遵守输出标准,否则使用它的代码可能会崩溃。

关于显示写入

TheScheme编程语言,第3版,第1页。 178

(display obj)
(display obj output-port)
returns unspecified

显示写入类似
但打印字符串和字符
直接在 obj 中找到。 弦乐
打印时不带引号或
斜杠,并打印字符
没有 #\ 符号。 例如,
两者(显示“(abc)”)
(display '("a b" c)) 将打印 (abc)。 因此,display 不应用于打印对象
旨在阅读
阅读display 主要用于打印消息,
obj 最常见的是字符串。

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

(display obj)
(display obj output-port)
returns unspecified

display is similar to write
but prints strings and characters
found within obj directly. Strings
are printed without quotation marks or
slashes, and characters are printed
without #\ notation. For example,
both (display "(a b c)") and
(display '("a b" c)) would print (a b c). Because of this, display should not be used to print objects
that are indended to be read with
read. display is useful primarily for printing messages, with
obj most often being a string.

柠栀 2024-07-29 10:00:25

如果您不想替换 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

浅浅 2024-07-29 10:00:25

在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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文