Consola#
Introducción#
Use print to display text in the Console in VEXcode IQ (2nd gen) or VS Code.
Todos los proyectos nuevos comienzan con el cursor en la fila 1.
By using print, you can display values to the Console.
Along with normal text and values, print can output special character sequences (escape codes) that change font color or clear the Console.
Nota: Al usar la consola VEXcode, debe conectarse al puerto serie de la consola antes de que se pueda imprimir cualquier salida en la consola.
imprimir#
print displays values on the Console.
Usage:
print(value, end)
Parámetros |
Descripción |
|---|---|
|
La cadena (entre comillas) o los números que se imprimirán en la consola. |
|
Optional. By default, Python will add a new line after each |
# Print a greeting
print("Hello there!")
New Lines#
By default, Python will add a new line after each print command. To print multiple values to the same line, use the end parameter.
# Print text on the same line
print("This text will be ", end="")
print("printed on the same line")
Cambiar el color de la fuente#
Puedes cambiar el color de la fuente al imprimir en la consola utilizando los siguientes códigos de color:
[31m- Red[32m- Green[34m- Blue[30m- Black[37m- White[33m- Yellow[91m- Orange[35m- Purple[36m- Cyan[97m- Transparent
All color codes need to follow an escape sequence = \033 in order to function.
You can either use this directly with print as a string:
# Print VEXcode in Red to the Console
print("\033[31mVEXcode")
Or, you can use it on its own to set all uses of print afterwards to the set color:
# Set the Console text color to Red before printing
print("\033[31m")
print("VEXcode")
Borra la consola#
By using \033[2J inside of print, you can clear the entire Console. This will also set the cursor back to row 1.
# Clear the Console after 2 seconds
print("VEXcode")
wait(2, SECONDS)
print("\033[2J")