Hi, i need to know What do you mean by Python literals
A literal is some notation that represents a built-in, or fixed value in code. For example, 1
is an integer literal, because whenever you write 1
in code, you’re actually just writing notation that represents the int
value of 1. Another example is a string literal, such as "hello world!"
. When you write that, you’re really just representing a string object.
It’s important to note that in Python, you can’t assign to a literal:
In [1]: 1 = len([1])
File "<ipython-input-1>", line 1
1 = len([1])
^
SyntaxError: cannot assign to literal
This raises an error since you’re trying to assign to 1
, which is a literal.