0
0
Pythonprogramming~10 mins

print() parameters and formatting in Python - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - print() parameters and formatting
Start print() call
Evaluate arguments
Apply sep between args
Add end string
Send output to console
print() ends
This flow shows how print() takes arguments, joins them with sep, adds end, then outputs to console.
Execution Sample
Python
print('Hello', 'World', sep='-', end='!\n')
Prints 'Hello-World!' by joining with '-' and ending with '!\n'.
Execution Table
StepActionArguments Evaluatedsep Usedend UsedOutput Produced
1Start print() call('Hello', 'World')-!\n
2Join arguments with sep'Hello' + '-' + 'World'-!\nHello-World
3Add end stringN/A-!\nHello-World!
4Send output to consoleN/A-!\nHello-World! (with newline)
5print() endsN/A-!\nN/A
💡 print() finishes after outputting the joined string with end appended.
Variable Tracker
VariableStartAfter Step 2After Step 3Final
args('Hello', 'World')('Hello', 'World')('Hello', 'World')('Hello', 'World')
sep'-''-''-''-'
end'!\n''!\n''!\n''!\n'
output_string'''Hello-World''Hello-World!\n''Hello-World!\n'
Key Moments - 3 Insights
Why does print() add a space by default between arguments?
By default, print() uses sep=' ' to join arguments. In the execution_table step 2, you see sep is '-' because we set it, but if not set, it is a space.
What happens if we don't specify end parameter?
If end is not given, print() uses '\n' (newline) by default. In the table, end='!\n' is used explicitly, but normally it ends with just '\n'.
Can print() output multiple arguments without converting them manually?
Yes, print() converts all arguments to strings automatically before joining with sep, as shown in step 2 where arguments are joined.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, what is the output string before adding end?
AHello-World
BHello World
CHelloWorld
DHello!World
💡 Hint
Check the 'Output Produced' column at step 2 in execution_table.
At which step does print() add the end string to the output?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the 'Action' column in execution_table where end is applied.
If we change sep to ',' and end to '.' what will be the final output string?
AHello-World!
BHello World.
CHello,World.
DHello, World.
💡 Hint
Refer to variable_tracker 'sep' and 'end' values and how they affect output_string.
Concept Snapshot
print(*objects, sep=' ', end='\n')
- Joins objects with sep string (default space)
- Ends output with end string (default newline)
- Converts all objects to strings automatically
- Useful for formatting output simply
Full Transcript
The print() function in Python takes any number of arguments and prints them to the console. It joins all arguments by a separator string called sep, which defaults to a space. After joining, it adds an end string, which defaults to a newline character. You can change sep and end to customize how the output looks. For example, print('Hello', 'World', sep='-', end='!\n') prints Hello-World! and moves to the next line. This visual trace shows each step: starting the call, joining arguments with sep, adding end, and sending output to the console. Variables like args, sep, end, and output_string change as the function runs. Remember, print() automatically converts all arguments to strings before joining. This makes it easy to print multiple values without manual conversion.