pxt-calliope/docs/blocks/variables/assign.md

37 lines
939 B
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# Assignment Operator
2017-03-16 15:57:41 +01:00
Use an equals sign to make a [variable](/blocks/variables/var) store the [number](/types/number)
or [string](/types/string) you say.
2016-03-26 00:47:20 +01:00
2016-05-25 00:36:04 +02:00
When you use the equals sign to store something in a variable, the equals sign is called
an *assignment operator*, and what you store is called a *value*.
2016-03-26 00:47:20 +01:00
2016-05-25 00:36:04 +02:00
### Storing numbers in variables
This program makes the variable `item` equal `5` and then shows it on the [LED screen](/device/screen).
2016-03-26 00:47:20 +01:00
````blocks
2016-05-25 00:36:04 +02:00
let item = 5
basic.showNumber(item)
2016-03-26 00:47:20 +01:00
````
2016-05-25 00:36:04 +02:00
### Storing strings in variables
2016-03-26 00:47:20 +01:00
2016-05-25 00:36:04 +02:00
This program makes the variable `name` equal `Joe` and then shows it on the [LED screen](/device/screen).
2016-03-26 00:47:20 +01:00
````blocks
2016-05-25 00:36:04 +02:00
let name = "Joe"
basic.showString(name);
2016-03-26 00:47:20 +01:00
````
### Notes
2016-05-25 00:36:04 +02:00
You can use the assignment operator with variables of
2017-03-16 15:57:41 +01:00
every [type](/types). A *type* is which kind of thing
2016-05-25 00:36:04 +02:00
a variable can store, like a number or string.
2016-03-26 00:47:20 +01:00
### See also
2017-03-16 15:57:41 +01:00
[variable](/blocks/variables/var), [types](/types)
2016-03-26 00:47:20 +01:00