Output

The print function prints output to the console.

hello.py
print("Hello World!")
Terminal
$ python hello.py 
Output
Hello World!

Objects are automatically converted to string representations for printing.

Reference: https://docs.python.org/3/library/functions.html#print

String Concatenation and Formatting

String concatenation is the operation of joining character strings. In Python, there are several ways to concatenation strings.

Comma

print("hello","world")

String Concatenation

print("hello" + " " + "world")

String Interpolation

print("{0} {1}".format("hello","world"))

Format Literals

Python 3.6 introduced format literals, with a more elegant syntax (less redundancy).

greeting = "hello"
who = "humans"
print(f"{greeting} {who}")

Last updated