Skip to content

Latest commit

 

History

History
60 lines (40 loc) · 866 Bytes

03_constants.md

File metadata and controls

60 lines (40 loc) · 866 Bytes

Constants

Constants (consts) are even like variables, but one thing is different in constants, Constant value cannot be changed.

for example:

# declare the const
$&name = 'the value'

println($&name)

output:

the value

To declare consts, you only need to put a & in the name of variable(location of that is not important).

$&const1 = 123
$&const2 = 'fsgdf'
# ...

When we try to change value of the const, we will get error:

$&name = 'the name'

$&name = 'new value'

output:

ConstError: "$&name" is const and cannot be changed...

also you can declare a constant, but set value of that later.

for example:

$&name # only declare constant, default value is `None`

# set value
$&name = 'parsa'

println($&name)

output:

parsa

But in the second time, error will be raised.