# Day 5 – Comments, Escape Sequences & the print() Function in Python

![](https://cdn.hashnode.com/uploads/covers/664f77938fc1f806b829b90b/2e5455be-275f-45c1-bd22-6ff99e0f9ed4.jpg align="center")

Welcome to **Day 5 of 100 Days of Python!**

Today, we will learn three useful concepts:

*   Python comments
    
*   Escape sequences
    
*   More options of the `print()` function
    

These concepts may look simple, but they are important for writing readable Python programs and controlling how output is displayed.

* * *

## 1\. Python Comments

A **comment** is text written in a Python program that is ignored by the Python interpreter during execution.

Comments are mainly used to:

*   Explain what a piece of code does
    
*   Make code easier to understand
    
*   Add notes for yourself or other developers
    
*   Temporarily prevent a line of code from executing while testing
    

### Single-Line Comments

In Python, a single-line comment starts with the `#` symbol.

Everything after `#` on that line is treated as a comment.

### Example 1

```python
# This is a single-line comment

print("This is a print statement.")
```

### Output

```text
This is a print statement.
```

The comment does not produce any output.

* * *

### Example 2: Comment After Code

A comment can also be written after a statement.

```python
print("Hello World!")  # Printing Hello World
```

### Output

```text
Hello World!
```

The Python interpreter executes the `print()` statement but ignores the comment.

* * *

### Example 3: Temporarily Disabling Code

Comments can also be useful when testing code.

```python
print("Python Program")

# print("Python Program")
```

### Output

```text
Python Program
```

The second `print()` statement does not execute because it has been commented out.

* * *

# 2\. Multi-Line Comments

Python does not have a special syntax specifically designed for multi-line comments.

If you want to write a comment across multiple lines, the recommended approach is to use `#` on each line.

### Example

```python
# This program checks whether p is greater than 5.
# If the condition is true, the first message is printed.
# Otherwise, the second message is printed.

p = 7

if p > 5:
    print("p is greater than 5.")
else:
    print("p is not greater than 5.")
```

### Output

```text
p is greater than 5.
```

* * *

## Triple-Quoted Strings

You may also see triple quotes being used for blocks of text:

```python
"""
This looks like a multi-line comment.
It is actually a multi-line string.
"""

p = 7

if p > 5:
    print("p is greater than 5.")
else:
    print("p is not greater than 5.")
```

### Output

```text
p is greater than 5.
```

Triple-quoted text is technically a **string literal**, not a comment.

Triple-quoted strings are commonly used for **docstrings**, which document functions, classes, and modules.

For example:

```python
def greet():
    """This function prints a greeting."""
    print("Hello!")
```

For normal comments, prefer `#`.

* * *

# 3\. Escape Sequences

An **escape sequence** is a special combination of characters used inside a string to represent characters or actions that would otherwise be difficult to write directly.

Escape sequences usually begin with a backslash (`\`).

For example, suppose we want to include double quotes inside a string that is already surrounded by double quotes.

This would cause a problem:

```python
print("This doesn't "execute" correctly")
```

Python cannot determine where the string ends.

We can use the `\"` escape sequence:

```python
print("This will \"execute\" correctly")
```

### Output

```text
This will "execute" correctly
```

* * *

## Common Escape Sequences

Here are some useful escape sequences:

| Escape Sequence | Meaning |
| --- | --- |
| `\n` | New line |
| `\t` | Tab |
| `\\` | Backslash |
| `\"` | Double quote |
| `\'` | Single quote |

### Example

```python
print("Hello\nPython")
```

Output:

```text
Hello
Python
```

The `\n` moves the output to a new line.

Another example:

```python
print("Name:\tSritesh")
```

Output:

```text
Name:   Sritesh
```

The `\t` inserts a tab space.

* * *

# 4\. More About the `print()` Function

So far, we have used `print()` to display text and numbers.

Python's `print()` function provides additional parameters that allow us to control how multiple values are displayed.

A simplified form of its syntax is:

```python
print(*objects, sep=' ', end='\n', file=None, flush=False)
```

The most commonly useful parameters for beginners are:

*   `objects`
    
*   `sep`
    
*   `end`
    

* * *

## `objects`

`print()` can display one or more objects.

```python
print("Hello")
print(10)
print("Python", 100)
```

Output:

```text
Hello
10
Python 100
```

When multiple objects are passed to `print()`, Python separates them with a space by default.

* * *

# 5\. The `sep` Parameter

`sep` stands for **separator**.

It controls what is placed between multiple objects.

The default value is a space:

```python
print("Python", "Java", "C++")
```

Output:

```text
Python Java C++
```

We can change the separator:

```python
print("Python", "Java", "C++", sep="~")
```

Output:

```text
Python~Java~C++
```

Another example:

```python
print("2026", "09", "12", sep="-")
```

Output:

```text
2026-09-12
```

* * *

# 6\. The `end` Parameter

By default, `print()` moves to a new line after displaying the output.

This happens because the default value of `end` is `"\n"`.

For example:

```python
print("Hello")
print("World")
```

Output:

```text
Hello
World
```

We can change the ending character.

```python
print("Hello", end=" ")
print("World")
```

Output:

```text
Hello World
```

We can also use another string:

```python
print("Hello", end="003\n")
print("World")
```

Output:

```text
Hello003
World
```

* * *

# 7\. Combining `sep` and `end`

The `sep` and `end` parameters can also be used together.

```python
print("Hey", 6, 7, sep="~", end="003\n")
```

Output:

```text
Hey~6~7003
```

Here:

*   `sep="~"` places `~` between `Hey`, `6`, and `7`
    
*   `end="003\n"` adds `003` after the final value and then moves to a new line
    

* * *

# 8\. Putting Everything Together

Here is a small program using comments, escape sequences, `sep`, and `end`:

```python
# Learning comments, escape sequences and print()

print("Hey! I am a \"Good Boy\".\nI am learning Python")

print("Hey", 6, 7, sep="~", end="003\n")

print("Hello!")
```

### Output

```text
Hey! I am a "Good Boy".
I am learning Python
Hey~6~7003
Hello!
```

* * *

# 9\. Common Mistakes

### Mistake 1: Forgetting the `#`

Incorrect:

```python
This is a comment
```

Python will try to interpret it as code.

Correct:

```python
# This is a comment
```

* * *

### Mistake 2: Incorrectly using quotes inside a string

Incorrect:

```python
print("He said "Hello"")
```

Correct:

```python
print("He said \"Hello\"")
```

Or use different quote types:

```python
print('He said "Hello"')
```

* * *

### Mistake 3: Confusing `sep` and `end`

Remember:

*   `sep` → controls the separator **between objects**
    
*   `end` → controls what is printed **after the final object**
    

* * *

# 10\. Quick Revision

### Comments

```python
# This is a comment
```

Comments are ignored by Python and are used to explain code or temporarily disable code.

### Escape Sequences

Escape sequences begin with `\`.

Common examples:

```text
\n  → New line
\t  → Tab
\\  → Backslash
\"  → Double quote
\'  → Single quote
```

### `print()`

Basic usage:

```python
print("Hello")
```

Using `sep`:

```python
print("A", "B", "C", sep="-")
```

Output:

```text
A-B-C
```

Using `end`:

```python
print("Hello", end=" ")
print("World")
```

Output:

```text
Hello World
```

* * *

# 11\. Key Takeaways

After Day 5, you should understand:

*   What comments are and why they are useful
    
*   How to create single-line comments using `#`
    
*   Why triple-quoted text is technically a string rather than a comment
    
*   What escape sequences are
    
*   How `\n`, `\t`, `\\`, `\"`, and `\'` work
    
*   How `print()` accepts multiple objects
    
*   How `sep` changes the separator between objects
    
*   How `end` changes what `print()` outputs after each call
    

These are small concepts, but they will appear frequently in Python programs as we move into variables, data types, conditions, loops, functions, and beyond.

* * *

## **📂 Day 5 Resources**

All notes and code for this day are available in the GitHub repository:

%[https://github.com/SriteshSuranjan/100-Days-of-Python/tree/main/05-Day05-Comments-and-Print] 

* * *
