Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Tutorial
  3. Python print() and Comments

Getting started · Tutorial 2

Python print() and Comments

Learn how to display text and values with print(), control separators and line endings, and document code with comments.

Open the compilerPractice exercises
beginner6 min readUpdated November 19, 20263 learning goals
On this page
  1. Printing values
  2. Controlling the line ending
  3. Comments
  4. Multi-line notes
  5. Practice

What you will learn

  • Display multiple values with print()
  • Change the separator and line ending
  • Write useful single-line and block comments
Before this lesson: Python Introduction: What Python Is and How to Run It

print() is often the first function you learn and one of the most useful debugging tools. It writes values to standard output and adds a newline by default.

Printing values#

Pass one or more values to print():

Python
print("Python")
print("Hello", "World")
print(42)
Expected output

Python Hello World 42

When you pass several arguments, Python inserts a single space between them. That is controlled by the sep keyword argument.

Python
print("2026", "11", "19", sep="-")
print("a", "b", "c", sep="")
Expected output

2026-11-19 abc

Controlling the line ending#

print() normally ends with a newline. Set end to change that:

Python
print("Loading", end="...")
print("done")
Expected output

Loading...done

This is useful for building one line from a loop:

Python
for number in range(5):
    print(number, end=" ")
print()

Comments#

A comment starts with # and continues to the end of the line. Python ignores it.

Python
# Calculate the total price
price = 19.99
quantity = 3
total = price * quantity  # tax is not included

print(total)

Use comments to explain why code does something, not to restate what the code already says. A comment such as # add one to count above count += 1 adds noise.

Multi-line notes#

Python does not have a dedicated block-comment syntax. By convention, triple-quoted strings are used for documentation strings (docstrings) inside functions, classes, and modules:

Python
def area(width, height):
    """Return the area of a rectangle."""
    return width * height

A docstring documents a public object and can be read with help(area). A bare triple-quoted string in the middle of unrelated code is usually not the best choice; several # lines are clearer.

Quotes matter

print("hello") prints text. print(hello) looks for a variable named hello and raises NameError if it does not exist.

Practice#

Predict the output before running this program:

Python
print("One", end=" ")
print("Two")
print("Three", "Four", sep=" | ")

Then run it in the compiler and compare. Change sep and end to see how the output changes.

Previous tutorialPython Introduction: What Python Is and How to Run ItNext tutorialPython Variables and Data Types

Related tutorials

beginner

Python Variables and Data Types

Understand variables, assignment, dynamic typing, and the core built-in types: str, int, float, bool, and None.

8 min read
beginner

Python Strings: Creation, Indexing, and Slicing

Create strings, access characters, take slices, use escapes, and explore common string operations.

9 min read

On this page

  1. Printing values
  2. Controlling the line ending
  3. Comments
  4. Multi-line notes
  5. Practice

Run the examples

Every Python block has a Run in compiler button that opens the code in a new tab.