In this tutorial, you will learn how to combine text and variables in Python to create messages that can change while your program is running. This is useful for displaying scores, names, levels, or any other information that updates dynamically, without needing to store the entire message in a separate variable first.
Необходимо е да се абонирате за FLLCasts.com, за да достъпите това видео
- #2600
- 12 Mar 2026
Python allows you to build strings from smaller pieces. You can combine fixed text (such as "Score: ") with variables (such as score) by using the "+" symbol.
Example:
from hub import light_matrix import runloop score = 10 async def main(): # Display the score message = "The score is: " + str(score) light_matrix.write(message) runloop.run(main())
Here is what happens:
"The score is: " is fixed text.
str(score) converts the number into text so it can be combined with the message.
The final result becomes "The score is: 10".
You can also combine the text and variable directly inside the brackets.
from hub import light_matrix import runloop score = 10 async def main(): # Display the score light_matrix.write("The score is: " + str(score)) runloop.run(main())