HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to Python: Print and RepeatVariablesData Types & NumbersStringsListsConditions (if / elif / else)Loops (for / while)FunctionsOperatorsDictionariesTuples & SetsError Handling (try / except)Classes (Object-Oriented)File OperationsComments & IndentationBooleans (True / False)Lambda & map / filterModules (import)InheritanceVariable Scope
REFERENCE
📖 Overview
🖥️ Output & Input
🔢 Numbers & Math
✍️ String
📋 List
🗂️ Dictionary & Set
🔁 Condition & Loop
🧩 Function
📁 File & Error
🔄 Type & Conversion
Python›Introduction to Python: Print and Repeat

Introduction to Python: Print and Repeat

From scratch, for someone who has never written code; the print command, variables, loops and functions — every line explained one by one, with colors.

Simple enough for a 5-year-old to understand

Your first words to the computer

Making the computer say something in Python is very easy. The "print" command writes everything you type inside quotes to the screen.

Your first program
1
print("Hello!")
print means "write to the screen". It shows the text inside the quotes.
Output / Inputprint means "write to the screen". It shows the text inside the quotes.
Output / Input
💡 Hint: Don't forget the quotes (" ") — text must always be inside quotes.

Let's write two lines

Each "print" writes a separate line. Let's write two, one below the other.

Example code
1
print("I am writing code")
Writes the first line to the screen.
Output / InputWrites the first line to the screen.
2
print("So much fun!")
Writes the second line. See — they came out one below the other.
Output / InputWrites the second line. See — they came out one below the other.
Output / Input

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (3 left)

1.What does the "print" command do?
2.In Python, what do we put text inside of?
3.Print exactly Hello World to the screen.

🎯 Expected output: Hello World

Loading editor…

Ready code templates

Copy-paste, run, adapt to your own needs. Every line explained.

Summing from 1 to N

A ready-made template that sums all numbers up to a given number. Change n, the rest stays the same.

Example code
1
n = 100
How far up we'll sum.
VariableHow far up we'll sum.
2
total = 0
The box where we'll accumulate the result; it starts at zero.
VariableThe box where we'll accumulate the result; it starts at zero.
3
for i in range(1, n + 1):
Loops from 1 to n (n INCLUDED).
LoopLoops from 1 to n (n INCLUDED).
4
total += i
Adds each number to the sum (total = total + i).
CodeAdds each number to the sum (total = total + i).
5
print(total)
Writes the result. For 1..100 the answer is 5050.
Output / InputWrites the result. For 1..100 the answer is 5050.
VariableLoopCodeOutput / Input

Print a list with numbers

A template that shows everything in your list as "1) ... 2) ...".

Example code
1
items = ["Apple", "Pear", "Cherry"]
The items we will print.
DataThe items we will print.
2
for index, item in enumerate(items, 1):
enumerate gives both the position number and the value (start from 1).
Loopenumerate gives both the position number and the value (start from 1).
3
print(f"{index}) {item}")
Writes something like "1) Elma".
Output / InputWrites something like "1) Elma".
DataLoopOutput / Input

About this topic

The first thing learned in every programming language is to make the computer say something. In Python, the way to do this is the print command: it prints everything you write inside the parentheses to the screen. This seemingly simple command actually teaches the core cycle of coding — write, run, see the result.

There is a reason for starting with print: it is the most widely used debugging tool in programming. Even years later, whenever you wonder what is inside a variable, the first thing you will do is print it to the screen. Therefore, think of print not as a "first lesson", but as a "tool you will use constantly".

What you will learn

  • printing text and numbers with print
  • Why quotation marks are mandatory
  • Why multiple print commands output on separate lines
  • Storing information in a variable and printing it
  • Combining text with a variable using an f-string

When to use?

You use print to see what is happening while the program runs: to check the result of a calculation, track which iteration a loop is on, or visually verify a line read from a file. In small scripts it's an output tool, in large projects it's a debugging tool.

Common mistakes

Wrong

print(Merhaba)

Writing Hello without quotes is considered a variable name, not text. Since you haven't defined such a variable, Python gives a "NameError: name 'Hello' is not defined" error.

Correct

print("Hello")

Wrong

print("Hello'

An opened quote must be closed with the same type. Mixed or missing quotes lead to a "SyntaxError: unterminated string literal" error — Python cannot figure out where the text ends.

Correct

print("Hello")

Wrong

print("Score: " + 100)

Text and numbers cannot be combined with a plus sign; Python says "TypeError: can only concatenate str (not "int") to str". Text and numbers are different types.

Correct

score = 100
print(f"Score: {score}")

Frequently asked questions

What is the difference between print and println?

There is no println in Python; that is a command in languages like Java and C#. Python's print command already moves to a new line on every call. If you don't want it to move to a new line, you can pass the end parameter to the print call.

Should I use single quotes or double quotes?

Both do the same thing, Python makes no distinction between them. Practical rule: if the text contains an apostrophe, use double quotes; if it contains double quotes, use single quotes; this way you don't need to write an escape character.

What is an f-string, why is it used?

When you put the letter f before the quotes, the variable name you write inside curly braces turns into that variable's value. It is the most readable and least error-prone way to combine text with variables; compared to combining with a plus sign, there is also no hassle with type conversion.

Summary

print is the only command for outputting to the screen in Python and also the most used debugging tool. Text is written in quotes, and f-strings are used to combine it with variables. These three things — print, quotes, f-strings — form the foundation of every subsequent lesson.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code