每个文字都是一个表达式吗?
让我们从一些定义开始:
表达式
是一个生成(返回)值的构造。literal
是表示固定值的符号。
我可以假设该文字是一个仅返回一个值的表达式。例如,文字 1
是一个返回值 1 的表达式。
我的方法有什么问题吗?还是文字总是意味着是表达式?
谢谢您的澄清。
Let's begin with some definitions:
- An
expression
is a construct that produces (returns) a value. - A
literal
is a notation for representing a fixed value.
I could assume the literal is a expression that returns exactly one value. E.g. the literal 1
is an expression that returns the value 1.
Is there anything wrong in my approach or does being a literal always imply being an expression?
Thank you for clarification.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

如果您考虑了特定于语言的异常(Python 文档字符串、C 宏等),那么您是正确的。一般来说,每个文字都是一个表达式。
If you account for language-specific exceptions (Python docstrings, C macros, etc.), you are correct. In general, every literal is an expression.