In this tutorial, you will learn how to change a variable from one type to another in Python. This process is called casting. It is especially useful when you need to convert numbers into text (strings) so they can be printed inside messages or displayed to users.
To access the full video please subscribe to FLLCasts.com
- #2599
- 12 Mar 2026
In Python, variables can store different types of data. For example:
Integers (int) – whole numbers such as 5 or 42
Strings (str) – text such as "Hello" or "Score"
Sometimes, you need to convert one type into another. This process is called casting.
To convert a number into text, you use the str() function.
Example:
from hub import light_matrix import runloop score = 10 async def main(): # Display the score message = str(score) light_matrix.write(message) runloop.run(main())
Here is what happens:
score stores the number 10
str(score) converts that number into the text "10"
The variable "message" now stores a string instead of a number
Even though it still looks like 10, Python now treats it as text.
You can also use str() directly inside the brackets.
Example:
from hub import light_matrix import runloop score = 10 async def main(): # Display the score light_matrix.write(str(score)) runloop.run(main())