Literal

During class of Python, I heard about Dictionaries Literals. I wonder why it's called literals. Q. What is a Literal literal is a value you write directly in your code. It is not a variable or a name => it's the actual data.(you can think of it as the raw data -> number, text, etc.) What is different from a Constant? a constant is a named variable whose value doesn't change final int MY_NUMBER = 42; -> like this(in here, the final keyword means constant), but 42 is literal. Why It's called a literal, not a value. A literal is the value as it appears literally in your code. int x = 10; 10 is a literal because you typed it directly into the code. it's called a literal because it's the literal representation of a value. But, value has a broader Concept. The word value means the result of anything -> it could be a literal a variable a result of a function call a complex expression eg. int x = a+b => Here, the value of x is not a literal -> it's calculated(computed). So we don't call it a "literal", even though it has a value.

Apr 19, 2025 - 22:17
 0
Literal

During class of Python, I heard about Dictionaries Literals. I wonder why it's called literals.

Q. What is a Literal

literal is a value you write directly in your code. It is not a variable or a name => it's the actual data.(you can think of it as the raw data -> number, text, etc.)

What is different from a Constant?

a constant is a named variable whose value doesn't change
final int MY_NUMBER = 42; -> like this(in here, the final keyword means constant), but 42 is literal.

Why It's called a literal, not a value.

A literal is the value as it appears literally in your code.

int x = 10;
  • 10 is a literal because you typed it directly into the code.
  • it's called a literal because it's the literal representation of a value.

But, value has a broader Concept. The word value means the result of anything -> it could be

  • a literal
  • a variable
  • a result of a function call
  • a complex expression eg. int x = a+b => Here, the value of x is not a literal -> it's calculated(computed). So we don't call it a "literal", even though it has a value.