Python Declaración Print(): Cómo imprimir con ejemplos

⚡ Resumen inteligente

Python print() function displays a message or object on the screen after converting it to a string. The examples below show how to print strings, blank lines, and multiple items, and how to control line endings.

  • 🖨️ Propósito: The print() function outputs strings and objects to the screen.
  • 🔤 Sintaxis: Call print(object(s)) with the value you want to display.
  • 🔁 Multiple Prints: Each print() call outputs on its own new line by default.
  • Blank Lines: Use “\n” or multiply it to print empty lines.
  • ➡️ end Parameter: Change the line ending, for example end=’ ‘, in Python 3.
  • ⚠️ Nota de la versión: Python 3 uses print() as a function; Python 2 used it as a statement.

Python Print() Statement

Python función de impresión ()

La función imprimir() en Python se utiliza para imprimir un mensaje específico en la pantalla. El comando de impresión en Python imprime cadenas u objetos que se convierten en una cadena mientras se imprimen en una pantalla.

Sintaxis:

print(object(s))

Cómo imprimir una cadena simple en Python?

La mayoría de las veces es necesario Imprimir cadenas en su construcción de codificación.

Aquí se explica cómo imprimir una declaración en Python 3:

Ejemplo: 1

Para imprimir el Bienvenido a Guru99, utilice el Python Imprima la declaración de la siguiente manera:

print ("Welcome to Guru99")

Salida:

Bienvenidos a Guru99

In Python 2, el mismo ejemplo se verá así

print "Welcome to Guru99"

Ejemplo 2:

Si desea imprimir el nombre de cinco países, puede escribir:

print("USA")
print("Canada")
print("Germany")
print("France")
print("Japan")

Salida:

USA
Canada
Germany
France
Japan

Cómo imprimir líneas en blanco

A veces es necesario imprimir una línea en blanco en su Python programa. A continuación se muestra un ejemplo para realizar esta tarea utilizando Python formato de impresión.

Ejemplo:

Imprimamos 8 líneas en blanco. Puedes escribir:

print (8 * "\n")

o bien:

print ("\n\n\n\n\n\n\n\n\n")

Aqui esta el codigo

print ("Welcome to Guru99")
print (8 * "\n")
print ("Welcome to Guru99")

Resultado

Welcome to Guru99







Welcome to Guru99

Comando de fin de impresión

By default, the print function in Python ends with a newline. This function comes with a parameter called ‘end’. The default value of this parameter is ‘\n’, i.e., the new line character. You can end a print statement with any character or string using this parameter. This is available only in Python 3 +.

Ejemplo 1:

print("Welcome to", end=' ')
print("Guru99", end='!')

Salida:

Bienvenidos a Guru99!

Ejemplo 2:

# ends the output with '@'
print("Python", end='@')

Salida:

Python@

Preguntas Frecuentes

In Python 2, print was a statement written as print “text”. In Python 3, print is a function called as print(“text”) with parentheses. Python 3 is the current standard, so always use the function form.

The sep parameter sets the separator placed between multiple items in one print() call. By default it is a space. For example, print(“a”, “b”, sep=”-“) outputs a-b instead of a b.

Use an f-string, such as print(f”Hello {name}”), or separate items with commas, such as print(“Hello”, name). F-strings are the modern, readable way to mix text and variables in Python 3.6 y posteriores.

Yes. AI assistants can spot missing parentheses, wrong quotes, or Python 2 syntax, and explain the exact error. They also suggest cleaner ways to format output, which helps beginners fix print-related mistakes quickly.

print() is a simple way to inspect data, model outputs, and intermediate values while building AI programs. Developers use it to trace how data flows through code, though logging libraries are preferred for larger projects.

Resumir este post con: