Courseiva
PCEP-30-02Chapter 2 of 16Objective 1.2

Python Basics: Comments, Print, and Input

What's the one thing every single programme you ever write needs to do: talk to the person using it and let you, the programmer, leave yourself notes? This chapter covers the three absolute foundational tools you need for that conversation: comments to write notes for yourself, print() to show results on the screen, and input() to get information from the user. These are not just 'nice to haves'—they are essential for passing the PCEP-30-02 exam and for writing any code that actually works with a human.

12 min read
Beginner
Updated Jul 23, 2026
Reviewed by Johnson Ajibi· Senior Network & Security Engineer · MSc IT Security

A simple way to picture Python Basics: Comments, Print, and Input

The Kitchen Recipe Card Analogy

Have you ever followed a recipe on a slightly smudged, handwritten card passed down from your grandmother?

That recipe card is the perfect blueprint for understanding Python basics. The recipe itself is the set of instructions—a programme—that tells you what to do. The ingredients list (flour, eggs, sugar) are the data your programme works with. Now, imagine your grandmother wrote a little note on the side of the card: 'Remember to preheat the oven first!' or 'This cake is best served with vanilla ice cream.' Those side notes are for you, the cook, to read. They aren't part of the actual recipe instructions; you wouldn't add 'preheat the oven first' into the mixing bowl. In Python, these notes are called comments. They are messages for the human reading the code, not for the computer to execute.

Next, after you've baked the cake, you want to tell your family what you've made. You shout, 'I made a chocolate cake!' That's the print() function in action. It sends output from your programme out into the world so you can see it. Finally, before you start, your grandmother might ask, 'What type of cake do you want to make?' You'd answer 'Chocolate' and write it down on the card. That moment of asking you a question and recording your response is exactly what the input() function does. It pauses the programme, asks the user a question, and captures the answer to use later. So, comments are the side notes, print is the announcement, and input is the question you answer before the real baking begins.

How It Actually Works

Let's break down these three concepts. Think of Python as a very literal and slightly stubborn friend who will only do exactly what you tell it, in the exact order you say it. Your code is a set of instructions for this friend.

Comments

A comment is a line of text in your code that Python completely ignores. It is there solely for you and other humans who might read your code later. Why would you need this? Because code can get complicated fast. A good comment explains 'why' you did something, not 'what' you did (the code itself should show the 'what'). To write a comment in Python, you use the hash symbol (#). Everything after the # on that line is ignored by Python. - Use comments to explain the purpose of a tricky section of code. - Use comments to temporarily disable a line of code while you are debugging (this is called 'commenting out'). - Do not write obvious comments like x = 5 # assign 5 to x. The code already shows that.

For example:

Calculate the total price including 20% VAT

total = price * 1.20

Python will skip the first line entirely and only execute the second line. Comments are essential for making your code maintainable and helping you remember your own logic when you come back to it next week.

The print() Function

The print() function is your programme's voice. It outputs text or values to the screen so you, the user, can see what is happening. Without it, a programme is silent—it might do amazing calculations, but you would never know the result.

To use it, you write print() and put what you want to show inside the parentheses. You can print a direct piece of text, called a string, by putting it in quotes (single ' or double " ).

print('Hello, World!') # This prints the text to the screen print(42) # This prints the number 42

You can also print the value stored inside a variable:

message = 'Welcome to PCEP-30-02' print(message)

By default, print() adds a newline character at the end, meaning each print() statement starts on a new line. You can change this behaviour with the end parameter, but that is a detail you will learn later. For the exam, know that print() is used for output and that it can handle multiple items if you separate them with commas, adding a space between them automatically.

The input() Function

The input() function does the opposite of print(): it takes information from the user and brings it into your programme. When Python hits an input() statement, it pauses the programme and waits for the user to type something and press Enter. That typed value is then returned as a string, which you should store in a variable.

name = input('What is your name? ') print('Hello, ' + name)

In the example above, the programme first prints the prompt 'What is your name? ' to the screen. It then waits. When you type 'Alice' and press Enter, the string 'Alice' is stored in the variable name. Then the next line runs and prints 'Hello, Alice'. The crucial thing for the exam is that input() always returns a string, even if the user types a number. If you want to do maths with that number, you must convert it using int() or float(). Forgetting this conversion is a classic beginner trap.

Combining Them

These three tools work together constantly. You use comments to document your code, input() to get data from the user, and print() to show the results. This cat-and-mouse of asking, calculating, and showing is the core of nearly every interactive programme you will build.

For the PCEP-30-02 exam, you must:

Know the correct syntax for a comment: #.

Know that print() is a built-in function for output.

Know that input() always returns a string and that you must convert it if you need a number.

Recognise that you cannot use a comment inside a string (a # inside quotes is just a # character).

A flowchart showing the typical order of operations: document with a comment, get input, convert if needed, process, and finally output with print().

Walk-Through

1

Write a comment for documentation

Start your script with a line starting with # to explain what the programme does. This helps anyone reading the file (including future you) understand the purpose without reading every line. Example: # This programme calculates your age in dog years.

2

Use input() to get user data

Call the input() function with a clear prompt string inside the quotes. This pauses the programme and shows the prompt to the user. For example, age = input('How old are you? ') stores the user's typed response as a string in the variable age.

3

Convert input data to the correct type

Because input() always returns a string, if you need a number for calculations, wrap the input() call with int() or float(). Example: dog_years = int(input('Enter age: ')) * 7. If you skip this step, multiplying a string by 7 would repeat the string seven times instead of doing maths.

4

Perform a calculation (if needed)

Use the converted data in your logic. Add comments to explain why you are doing something non-obvious. For example, # Multiply by 7 because one human year equals seven dog years. This is where the real work of the script happens.

5

Use print() to display the result

Call the print() function with the result you want to show. You can combine text and variables using commas or f-strings. Example: print('You are', dog_years, 'dog years old.') This outputs the answer to the screen so the user knows what the programme calculated.

What This Looks Like on the Job

Let's walk through a realistic business scenario at a small online bookshop. A junior IT analyst is asked to write a simple script that helps a manager calculate the final price of a bulk book order after a discount.

Step 1: The analyst opens a text editor and starts writing a Python script. Before she writes any code, she adds a comment at the top of the file to explain the script's purpose. This is vital because the manager might share this script with someone else next month, and they need to understand what it does without having to decode every line. She writes:

Final price calculator for bulk book orders

This script takes the number of books and the price per book, then applies a 15% bulk discount.

These comments are the digital equivalent of a sticky note on a report. They cost nothing and save hours of confusion later.

Step 2: The script needs to ask the user for input. The manager is not a programmer, so the script must be user-friendly. The analyst uses the input() function with a clear prompt. However, she remembers the key detail from her PCEP-30-02 studies: input() returns a string. The manager will type a number (like '45'), but the script cannot do maths on the string '45'. So she wraps the input() call inside the int() function to convert it immediately.

num_books = int(input('Enter the number of books in the order: ')) price_per_book = float(input('Enter the price per book in pounds: '))

She uses float() instead of int() here because the price might include pence (e.g., 8.99). This is a professional touch that prevents errors.

Step 3: With the numbers now safely stored as integers and floats, the analyst performs the calculation. She writes a comment to explain the discount logic, again for future readers.

Apply 15% bulk discount

1.0 - 0.15 calculates the remaining fraction after the discount

discounted_price = price_per_book * 0.85 total_cost = num_books * discounted_price

Step 4: The script must now show the manager the result. The analyst uses the print() function to display the total cost. She formats the output to be clear and professional, using an f-string (a modern way to embed variables inside text).

print(f'The total cost for {num_books} books after a 15% discount is: £{total_cost:.2f}')

The :.2f part is a format specifier that rounds the price to two decimal places, ensuring it looks like proper currency (£45.20, not £45.199999).

Step 5: Finally, the analyst runs the script. The programme pauses at the first input() line, waiting for the manager to type the number of books. After the manager provides this and the price, the script calculates and prints a clean result. Because she used comments, the manager or another colleague can open the file six months later and immediately understand the logic. This script, born from three simple Python basics—comments, print(), and input()—saves the company hours of manual calculation every month.

How PCEP-30-02 Actually Tests This

The PCEP-30-02 exam tests these three concepts very directly. You will not have to write a full programme from scratch, but you will have to read short code snippets and predict the output or identify errors. Here is precisely what you need to know.

Comments

The exam loves to test your understanding of what Python does with a comment. The key fact is: Python ignores everything after a hash symbol (#) on that line, until the line ends. Questions often show you a line of code with a comment after it, like print('Hello') # this prints hello, and ask you what output it produces. The answer is 'Hello' because the comment part is ignored.

Common traps:

A # symbol inside a string is not a comment. In print('# not a comment'), the hash is just a character being printed.

A comment cannot span multiple lines. Each line must start with its own #. (Python does have multi-line strings using triple quotes, but they are not true comments.)

The print() Function

This is a favourite. You must know: - print() can take multiple arguments separated by commas: print('a', 'b', 'c') outputs a b c (with spaces). - print() automatically adds a newline at the end. If you want to stay on the same line, you can set end=''. - print() can output any data type: strings, integers, floats, lists, etc. - The difference between print('5' + '3') which outputs '53' (string concatenation) and print(5 + 3) which outputs 8 (integer addition).

Exam trap: They will show you a line like print(5 + 3) and ask for the output. Beginners often answer '53' because they see strings everywhere. The correct answer is 8 because 5 and 3 here are numbers, not strings in quotes.

The input() Function

This is the most error-prone concept for beginners. The exam will test your understanding that input() ALWAYS returns a string, even if the user types a number.

Exam trap pattern: They show a snippet: num = input('Enter a number: ') # user types 10 result = num * 3 print(result) Many beginners think the output is 30. But the correct output is '101010'. Why? Because num is a string ('10'), and multiplying a string by an integer repeats the string. So '10' * 3 equals '101010'. To get 30, you must first convert: num = int(input(...)).

Key definitions to memorise:

Built-in function: A function that is always available in Python without needing to import any module. print() and input() are built-in functions.

String: A sequence of characters enclosed in quotes (single or double).

Concatenation: Joining two strings together with the + operator.

Type conversion: Changing one data type to another, e.g., int('10') converts the string '10' to the integer 10.

The exam will present multiple-choice questions and single-select (one correct answer) or multiple-select questions. They love asking 'What is the output of the following code?' with a snippet that mixes these concepts incorrectly, waiting for you to fall for the input() string trap.

Key Takeaways

The hash symbol (#) begins a comment, and everything after it on that line is ignored by Python.

The print() function sends output to the screen for the user to see.

The input() function always returns a string, even if the user types a number.

To use a number from input() in mathematics, you must convert it with int() or float().

A hash symbol inside quotes is just a character, not a comment.

Comments have zero effect on programme performance and are purely for human readability.

print() can accept multiple items separated by commas and automatically adds spaces between them.

You cannot use the result of print() in a calculation because it returns the special value None, not the text it printed.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

print()

Outputs data to the screen so the user can see it.

Does not pause the programme execution.

Returns the special value None, which cannot be used in arithmetic.

input()

Retrieves data from the user through keyboard entry.

Pauses the programme until the user presses Enter.

Always returns a string that must be converted for numeric use.

String (e.g., '5')

Enclosed in single or double quotes.

Using + between two strings concatenates them (e.g., '5' + '3' = '53').

Multiplication repeats the string (e.g., '5' * 3 = '555').

Integer (e.g., 5)

Written as a plain number without quotes.

Using + between two integers adds them (e.g., 5 + 3 = 8).

Multiplication multiplies the values (e.g., 5 * 3 = 15).

Inline Comment

Appears on the same line as code, after a statement.

Used for brief explanations of a specific line.

Example: x = x + 1 # increment counter

Block Comment (full-line)

Occupies its own line, starting with #.

Used for describing the purpose of a section or function.

Example: # This function calculates the square root.

int('10')

Converts a string to an integer.

Used when you need to perform arithmetic on user input.

Raises a ValueError if the string is not purely numeric (e.g., 'abc').

str(10)

Converts an integer to a string.

Used when you need to combine a number with other text for output.

Works on any data type, not just integers.

Watch Out for These

Mistake

I can use the hash symbol (#) inside a string to make a comment in the middle of printed text.

Correct

A hash symbol (#) inside quote marks (single or double) is just a character in the string, not a comment. A comment only starts with # outside of a string.

Beginners often think the # works 'everywhere' as a comment, but Python treats strings as literal text. The comment symbol only has special meaning at the code level, not inside data.

Mistake

The input() function returns a number if the user types a number, so I can do maths on it straight away.

Correct

input() always returns a string, regardless of what the user types. You must explicitly convert it using int() or float() before performing arithmetic.

This mistake is incredibly common because it feels intuitive: 'I typed 5, so I should get 5, not '5'.' But Python is strict about types, and treating a string as a number causes errors or unexpected results like string repetition.

Mistake

Comments slow down programme execution, so I should avoid them in production code.

Correct

Comments are completely ignored by the Python interpreter. They have zero impact on runtime speed. They exist solely for human readers.

New programmers often worry about performance and mistakenly believe any extra text will make the code slower. This is a misunderstanding of how the interpreter processes code—it skips comments entirely before execution.

Mistake

You can use the print() function to store data for later use in the programme.

Correct

print() only sends data to the screen for display. It does not return a value that you can capture or store in a variable. If you want to keep data, use a variable assignment.

Because print() 'shows' you something, beginners assume it also 'gives' that value back to the programme. They try to write something like result = print('hello'), but result gets the value None, not 'hello'.

Mistake

You must put parentheses around the prompt in input() like this: input(('Your name: ')).

Correct

The correct syntax is input('Your name: '). You only need one pair of parentheses for the function call. Double parentheses are a syntax error or create a tuple.

New learners sometimes overcompensate when they are unsure about function syntax. They see parentheses in examples and add extras 'just in case', leading to a confusing error message.

Mistake

Comments are only useful for other people; I do not need them for my own small projects.

Correct

Comments are crucial for your own future self. After a week away from a project, you will forget the rationale behind a convoluted piece of logic. Comments save you from having to re-read and re-debug your own code.

It is easy to think of code as something you write and understand forever. But memory fades, and code that seems obvious now will look cryptic later. This misconception causes huge time loss in real-world development.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

Does the hash symbol in a comment have to be at the start of the line?

No. A comment can start at the beginning of a line (a full-line comment) or after some code (an inline comment). For example, x = 5 # this is a comment. Everything after the # on that line is ignored.

What happens if I forget to convert input() and do maths anyway?

If you have a string and try to add it to a number, Python raises a TypeError because it does not know how to combine a string and an integer. If you use the * operator, it will repeat the string, which is probably not what you wanted. Always convert using int() or float().

Can I use print() to print multiple lines at once?

Yes. You can use a triple-quoted string (''' or """) inside print() to print multiple lines. Each line break in the string becomes a new line in the output. For example, print('''Line 1\nLine 2\nLine 3''').

What is the difference between print('5' + '3') and print(5 + 3)?

The first example concatenates two strings, producing the string '53'. The second example adds two integers, producing the integer 8. The quotes determine the data type.

Can I use single quotes or double quotes for strings in print() and input()?

Yes, both are fine in Python. You must be consistent (start and end with the same type). Single quotes are more common, but double quotes are useful if your string contains an apostrophe (e.g., print("It's a cat").

Why does my input() prompt appear but the programme seems stuck?

The programme is not stuck; it is waiting for you to type something and press the Enter key. input() pauses execution until it receives that Enter press. Type your answer and press Enter to continue.

Can I use a comment to hide multiple lines of code at once?

Not with a single #. Each line needs its own #. For multi-line disabling, you can use triple quotes (""") to create a multi-line string that Python evaluates but does nothing with, but this is not a true comment and can cause issues. The proper way for a single-line comment is # at the start of each line.

Keep going

You've finished Python Basics: Comments, Print, and Input. Continue through the PCEP-30-02 study guide to build a complete picture of the exam.

Done with this chapter?