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())
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons
Level A: Python Foundations – Robotics with LEGO SPIKE Prime
This is the first level of the LEGO Robotics Curriculum with Python, designed for students in grades 2, 3, and 4.
In this robot adventure, students learn to control robots using real Python code, while teachers guide them through their first steps in text-based programming. Throughout the level, students build a variety of LEGO SPIKE Prime robot models and program them to move, turn, and complete tasks with increasing precision.
Step by step, students learn how to read, understand, and write their own Python programs. Through fun and creative challenges, they bring their robots to life and discover how code can control movement, solve problems, and interact with the world. Along the way, they explore concepts such as navigation, obstacle avoidance, and sensor-based behavior.
The curriculum is designed to help teachers introduce programming in an engaging and approachable way while giving students plenty of opportunities to experiment, test ideas, and develop confidence in their coding skills.
By the end of the level, students apply everything they have learned in an exciting robotics competition. Using their own programs and robot designs, they complete missions on a competition field with boxes, putting their coding, engineering, and problem-solving skills to the test.
- 46
- 4:32
- 78
Lesson 5 - Educational toy: Learn to read the clock
Remember to give students regular feedback. It is important to provide clear and structured feedback, including grades or ranks. Today, you will need to assess your students by following this article.
- 7
- 6
- 14
- 3d_rotation 1