Define a variable
What is a variable? Try think about when you doing math, there must be some intermediate variables to store the numbers (results), right? In programming, a variable is a container to store data. You can think of it as a box that holds a value. The value can be a number, a string, a list, or any other data type.
In K, define a variable is simple. If you want to define a variable called x
and assign a value 10
to it, you can write:
k
x = 18
The =
is the assignment operator. It assigns the value on the right to the variable on the left. In this case, the value 18
is assigned to the variable x
.