What are constants and literary constants?

I am learning Python and I'm just confused with Literal constants and constants. What it is? For what purpose do we use them? What is their difference from a normal variable?

Many thanks.

Edit:

I am a true beginner. As a beginner, how can I say, I know nothing about the programming world. How would I not know what an expression is, and vice versa.

I learn python using the book "A byte of python", and somewhere in the book I came across a section that talks about literals and constants. I share the section:

5.2. Letter constants

An example of a literal constant is a number like 5, 1.23 or a string like "This is a string" or "This is a string!" ..

It is called a literal because it is literal - you use its meaning literally. The number 2 always represents and nothing more - this is a constant, because its value cannot be changed. Therefore, all of these are called literal constants.

Where he says: "It is called literal because it is literal, you use its meaning literally," I just do not get this part. What is the book trying to say that we use meaning literally? the indefinite point is that the number 2 is a constant, because the value cannot be changed. How is this possible? we can change it, for example:

stack = 2
stack = 3

-, 2 , Stack ( 2, , , , ) 3. 2. , , , . , .

+4
1

OP

- ; , , . REPL :

>>> 2
2
>>> 'hello'
'hello'

2 hello , , , (, , , ). :

stack = 2
stack = 3

(, , , , 2) - stack. , stack 2. , stack = 3, 2; stack , 3.

, " " ; , 2 'John' .. . ( , ), Python. - , , stack = 2, , stack, . Python .

:

-, None, True False ( , ) :

, , , . (, 42, 3.14 1.6e-10) (, "Hello, world" ). , .

"", " " Python. Python , True False None, " " Python 2.X, :

True = False
if True:
    print 'Hey' 
else:
    print 'WAAAT!'

, . , , .

: True False .. - Python 3.x, , True = False, SyntaxError: assignment to keyword.

+7

Source: https://habr.com/ru/post/1543872/


All Articles