print()
print() shows values on screen, separated by a space and followed by a newline.
Used in 129 lessons of the course, from 00.01.
print() is the function that writes text to your program's output. You can pass one value or several, separated by commas. If they aren't strings, Python converts them with str() for you.
By default, it puts a space between values and a newline at the end. You can change that with the keyword arguments sep and end.
print("a", "b", sep="-", end="!\n")
In the course you will see lines like print("Python version :", platform.python_version()): a label and a value, separated by a space. It is the quickest way to see what a variable holds or what a call returned, which is why it shows up in almost every lesson.
Reach for it when: you want to see a value, check a result, or show a message while your program runs.
Examples
Common mistake
print("Total:" + 5)Why: The `+` operator can't join a string and an int. Python doesn't convert the number for you in that case.
How to write it: Pass the values separated by commas: print("Total:", 5), or use an f-string.
Common mistake
print
print("done")Why: Without parentheses, `print` only names the function and doesn't call it. Nothing visible happens, and there is no error.
How to write it: Call the function with parentheses: print().
