In this tutorial, you’ll learn how to change a variable from one type to another in Python. This is called casting. It’s especially useful when you need to turn numbers into text (strings) so they can be printed inside messages or displayed to users.
Необходимо е да се абонирате за FLLCasts.com, за да достъпите това видео
- #2599
- 12 Mar 2026
In Python, variables can store different kinds of data. For example:
Integers (int) – whole numbers like 5 or 42
Strings (str) – text like "Hello" or "Score"
Sometimes you need to change one type into another. This is where casting comes in.
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’s what happens:
score stores the number 10
str(score) converts that number into the text "10"
The variable "message" now holds a string instead of a number
Even though it still looks like 10, Python now treats it as text.
This can be done inside the brackets as well.
Example:
from hub import light_matrix import runloop score = 10 async def main(): #Display the score light_matrix.write(str(score)) runloop.run(main())