Skip to content

print()

Use to print output / result on our console.

Usage

Syntax:

python
print()

Simple usage

Code:

print.py

python
print("Hello, World!")
print("This is a simple print statement in Python.")
print(1234)

Result:

Hello, World!
This is a simple print statement in Python.
1234

Output multiple content

  • can use + or , to join multiple content
python
name = "Alice"
print("Hello, " + name + "!")
print("Hello,", name, "!")

Output:

Hello, Alice!
Hello, Alice !

INFO

  • use \n end of the "" of a print()
py
print("Hello World \n")
print("This has a line blank on above")

Results:

Hello World 

This has a line blank on above
  • add end="" params to replace "\n" by default.
py
print("Hello")
print("World")

print("Hello", end="")
print("World")

Results:

Hello
World
HelloWorld

Box Drawing

By using \t as a escape character that represents a horizontal tab

  • \t is great for quick console formatting
py
print("Name\tAge\tCity")
print("Alice\t25\tNew York")
print("Bob\t30\tLondon")

Results:

Name    Age     City
Alice   25      New York
Bob     30      London