1. Print function
print() is a built-in function: code Python already provides, which you run by calling it. A call is the function name followed by parentheses, and the values between the parentheses are its arguments.
Its signature is:
*values— any number of values, printed one after another.sep— the text placed between values. Default: a space.end— the text placed after the last value. Default: a newline.
Values passed by position, as in print("a", "b"), are positional arguments. sep and end are written as name=value, so they are keyword arguments. They are keyword-only: you must pass them by name (sep="-"), never as extra positional arguments.
\n is the escape sequence for a newline: it moves to the next line. This lesson goes through the pieces of print() one at a time: quotes, numbers, several values, sep, end, escaped quotes and multi-line strings. You can always inspect the function with help(print).
Print your first line
Text goes inside quotes. print() shows it in the console.
Print exactly:
Single or double quotes
Both "double" and 'single' quotes create a string. Use whichever you prefer.
Print exactly, using single quotes:
Print numbers
Numbers don't need quotes. print(42) shows 42, while print("42") shows the same text.
Print exactly:
Print several values
Each value inside the parentheses is an argument. Separate them with commas and print() shows them one after another, joined by a space.
Print exactly with a single print() and three positional arguments:
Change the separator
sep is a keyword-only parameter: write it by name, after the positional values. It replaces the space printed between them.
Print exactly using three positional arguments and sep="-":
Control the line ending
Every print() ends with a newline, so the next print() starts on a new line. end is also keyword-only and replaces that newline.
Print exactly using two print() calls and end:
Quotes inside a string
To put a " inside a "..." string, escape it with a backslash: \".
Print exactly, using double quotes:
Multi-line strings
Triple quotes """...""" let a string span several lines.
Print exactly: