Placement Prep

Python print() Function: How to Print Output in Python

Complete guide to Python's print() function: syntax, sep, end, file, flush parameters, f-strings, and output formatting patterns for placement coding rounds.

By FACE Prep Team 5 min read
python python-programs placement-prep coding-interview python-basics

Python’s print() function has five parameters, and placement coding rounds test all of them, not just the first.

The print() function: syntax and parameters

The Python documentation for print() defines the full signature as:

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

Each parameter controls one specific part of the output:

  • *objects — one or more values to display. Python converts non-string values to strings automatically using str().
  • sep — the string inserted between multiple values. Default: a single space ' '.
  • end — the string appended after all values. Default: a newline '\n'.
  • file — the output stream. Default: sys.stdout (the console).
  • flush — whether to force-flush the output buffer immediately. Default: False.

The star before objects means print() accepts any number of positional arguments. That is why print('a', 'b', 'c') works without wrapping the values in a list. You can also call print() with no arguments at all to emit a blank line, which is occasionally useful for spacing output blocks apart.

Printing strings, numbers, and variables

Printing a string

print('Hello, World')
print("Practising Python for campus placements")

Output:

Hello, World
Practising Python for campus placements

Single quotes and double quotes are interchangeable in Python. The practical difference: if your string contains an apostrophe, use double quotes to avoid escaping. Both work on every platform and on every campus test system that accepts Python.

Printing a number

marks = 85
print(marks)

Output:

85

No explicit conversion is needed. print() calls str() on the value internally before displaying it, so integers, floats, booleans, and lists all print directly without a wrapper.

Printing strings and variables together

Three approaches work here, and all three appear in placement interview question banks:

subject = "Python"
score = 95

# Comma-separated: adds a space between each argument automatically
print("Subject:", subject, "Score:", score)

# String concatenation: requires explicit str() for non-string values
print("Score: " + str(score))

# f-string (Python 3.6 and later)
print(f"Subject: {subject}, Score: {score}")

Output:

Subject: Python Score: 95
Score: 95
Subject: Python, Score: 95

Placement test auto-graders compare output character by character. If the expected output is Subject: Python Score: 95, the comma-separated approach matches exactly because the space comes from the default sep. If the spec requires a comma between the values, the f-string approach is the precise tool.

Controlling format with sep and end

The sep parameter

The default separator between multiple values is a single space. Any string can replace it.

# Default space
print('TCS', 'NQT', '2026')           # TCS NQT 2026

# Hyphen separator
print('TCS', 'NQT', '2026', sep='-')  # TCS-NQT-2026

# No separator
print('TCS', 'NQT', '2026', sep='')   # TCSNQT2026

# Comma-space separator
print('CSE', 'ECE', 'EEE', sep=', ')  # CSE, ECE, EEE

The sep parameter only affects the spacing between positional arguments. It has no effect when you call print() with a single argument.

The end parameter

By default, each print() call ends with a newline, so the next output appears on a fresh line. Changing end keeps the cursor on the same line.

print("Round 1", end=' ')
print("Round 2", end=' ')
print("Round 3")

Output:

Round 1 Round 2 Round 3

Compare to default behaviour where three separate print() calls produce three separate lines. AMCAT and CoCubes coding sections often give exact expected-output specifications. The end parameter is the tool to match a “same-line” output spec without restructuring the loop logic. Set end='' for no gap, end=' ' for a space, or any other string to append custom text.

Combining sep and end

print("21", "05", "2026", sep='-', end='\n')
print("21", "05", sep='-', end='-2026')

Output:

21-05-2026
21-05-2026

Both lines produce identical output through different means. Interviewers sometimes ask which argument combination produced a given format, so understanding how sep and end interact is worth running once yourself.

Formatting output with f-strings

Python supports three string formatting styles. All three appear in placement interview questions, often in the same test session.

name = "Riya"
score = 92

# Percent formatting (legacy style, still tested in older question banks)
print("Name: %s, Score: %d" % (name, score))

# .format() method (common in codebases from 2018 to 2022)
print("Name: {}, Score: {}".format(name, score))

# f-string (Python 3.6 and later, preferred for new code)
print(f"Name: {name}, Score: {score}")

All three produce:

Name: Riya, Score: 92

The % style is the oldest and often appears in legacy interview question PDFs. The .format() style is cleaner and still widely used in production code written before 2020. f-strings are the current standard for new code because they are the most readable and slightly faster at runtime.

f-strings support full Python expressions inside the braces, not just variable names:

a = 7
b = 3
print(f"{a} + {b} = {a + b}")
print(f"{a} * {b} = {a * b}")

Output:

7 + 3 = 10
7 * 3 = 21

The Python Input and Output tutorial covers all three formatting styles with format specifiers for decimal places, column width, and alignment.

Aligned table output

Formatted tabular output is a category that appears in aptitude-plus-coding combined rounds. The f-string format specifiers :<N (left-align) and :>N (right-align) control column width:

items = [("Pen", 10), ("Notebook", 150), ("Bag", 800)]
for item_name, price in items:
    print(f"{item_name:<12} Rs.{price:>5}")

Output:

Pen          Rs.   10
Notebook     Rs.  150
Bag          Rs.  800

Without the width specifiers, the columns would be ragged. Placement tests on formatted-report output check that you can pad values to consistent widths.

Printing to a file

with open("results.txt", "w") as f:
    print("Score: 95", file=f)
    print("Grade: A", file=f)

Nothing appears on the console. Both lines write to results.txt. Some coding rounds ask for file output rather than console output, particularly in off-campus assessments.

Flush for real-time display

import time
for step in range(1, 4):
    print(f"Step {step} complete", flush=True)
    time.sleep(0.5)

Without flush=True, output in a loop may buffer and appear all at once when the script finishes. Setting flush=True forces each line to display as soon as it is printed. This appears more often in practical Python questions and internship screening rounds than in standard campus tests, but knowing it avoids a baffling debugging situation.

What to practise next

Every program in the Python basic programs guide uses print() to display results. Working through those programs builds pattern-recognition for matching exact output specs under timed conditions. That skill costs marks when students know the algorithm but format the output slightly wrong.

For programs that classify characters, the uppercase/lowercase/digit/special character checker shows how to combine character comparisons with print() output in a single cohesive program.

The Python calculator program ties print(), input(), and conditional logic together. It is a solid capstone exercise once you are comfortable with formatting.

Once you can control print() output precisely, building scripts that do something real is the natural next step. TinkerLLM’s Python environment lets you run every print() variant from this article interactively and then extend the same scripts to call an LLM API, a pattern that has started appearing in product-company internship screening rounds.

Primary sources

Frequently asked questions

What are all five parameters of Python's print() function?

The five parameters are: objects (one or more values to display), sep (separator between values, default a space), end (string appended after the last value, default newline), file (output stream, default sys.stdout), and flush (whether to flush the buffer immediately, default False).

How do I print multiple values on the same line in Python?

Pass multiple values to one print() call and set end='' to suppress the automatic newline. Example: print('Hello', end=' ') followed by print('World') prints both on a single line.

What is an f-string and how do I use it with print()?

An f-string is a string literal prefixed with f. Expressions inside curly braces are evaluated at runtime. For example: name = 'Riya'; print(f'Hello {name}') prints 'Hello Riya'. f-strings require Python 3.6 or later.

Can I use print() to write output to a file?

Yes. Open a file with open('output.txt', 'w') and pass the file object to the file parameter: print('Result: 95', file=f). Nothing appears on the console; the output goes to the file instead.

How do I control the separator between values in print()?

Use the sep parameter. print('2026', '05', '09', sep='-') produces '2026-05-09'. The default is a single space. Set sep='' for no separator at all.

Why does print() add a newline at the end by default?

The default value of the end parameter is a newline character. To suppress it, set end='' or end=' '. This matters when building output across multiple print() calls that should appear on one line.

Build AI projects

A self-paced playground for building with LLMs.

TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.

Try TinkerLLM (₹299 launch)
Free AI Roadmap PDF