2

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.

1
  • 1
    I'm not sure if there's a rigid definition of "literal". OTOH, I think you'd be hard-pressed to find anything commonly considered a literal that isn't a valid expression. Commented Nov 21, 2011 at 19:44

2 Answers 2

2

If you account for language-specific exceptions (Python docstrings, C macros, etc.), you are correct. In general, every literal is an expression.

Sign up to request clarification or add additional context in comments.

Comments

0

That's my understanding. To think of it another way:

4-3 is one way of expressing 1

1 is another way of expressing 1

They are both expressions, because they both express a value (1). But 1 is also a literal - because it's literally 1.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.