В момента ресурсът е наличен само на английски

Combining Text and Variables in Python Pro Preview

In this tutorial, you’ll learn how to combine text and variables in Python to create messages that can change while your program runs. This is useful for displaying scores, names, levels, or any information that updates, without needing extra steps to store the full message first.

Необходимо е да се абонирате за FLLCasts.com, за да достъпите това видео

Абонирай се

  • #2600
  • 12 Mar 2026

Python lets you build strings from pieces. You can mix fixed text (like "Score: ") with variables (like score) by using "+".

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’s what happens:

  • "The score is: " is fixed text.

  • str(score) converts a number into text so it can be joined.

  • The result is "The score is: 10".

This can be done inside the brackets as well.

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())