print() sep and end Parameters Explained
Parameters: Extra Settings for a Function
You already know two things print() does on its own:
- It puts a space between the items you give it.
- It ends every line, so the next
print()starts on a new line.
Most of the time that's what you want. But you can change both! You do it with parameters.
A parameter is a named setting you can give a function. You write its name, an = sign, and the value you want, inside the brackets, after your items:
print("apple", "banana", sep=" | ")apple | banana
Here sep is the parameter, and " | " is the value you chose for it. The value you pass is called an argument.
Think of ordering a cup of tea: "tea, please" gets you the normal one. "Tea, with no sugar" changes one setting. The tea is your text, and "no sugar" is a parameter.
print() has two parameters you'll use all the time:
| Parameter | Controls | Normal value |
|---|---|---|
sep | what goes between the items | one space |
end | what comes after the last item | a new line |
If you don't set them, print() uses the normal values. That's why everything you printed so far had spaces between items and ended with a new line.
Parameters are named settings: name=value, after your items.