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
print()input()f-string
🔢 Numbers & Math
✍️ String
📋 List
🗂️ Dictionary & Set
🔁 Condition & Loop
🧩 Function
📁 File & Error
🔄 Type & Conversion
Python›REFERENCE›Output & Input
🖥️

Output & Input

Printing to the screen and taking input from the user.

CommandDescription
print()Writes the given values to the screen.
input()Takes text input from the user via the keyboard.
f-stringEmbeds a variable/expression inside text.

print()

Try it yourself →

Writes the given values to the screen.

Syntax

print(*values, sep=' ', end='\n')

Description

Prints the value(s) inside the parentheses to the screen. You can pass several values separated by commas; by default it puts a space between them and moves to a new line at the end. You can change this behavior with sep and end.

Parameters

*valuesOne or more values to print.
sep(optional)The separator placed between values (default: a space).
end(optional)The text added at the end of the line (default: a newline).

Returns

Returns nothing (None); it writes to the screen.

Example

print("Hello", "World")
print("A", "B", "C", sep="-")
print("side by side", end=" ")
print("continues")

Expected output

Hello World
A-B-C
side by side continues

When to use?

The most-used command for showing a program's result to the user and for seeing variables' values while debugging.

Common mistakes

  • ⚠️ Forgetting to put the text in quotes: print(Hello) gives an error, print("Hello") is correct.
  • ⚠️ Forgetting that sep and end are only given as keyword arguments.

input()

Try it yourself →

Takes text input from the user via the keyboard.

Syntax

input(message)

Description

Prints an optional message to the screen and returns the line written by the user as TEXT (str). If you need a number, you must convert it using int() or float().

Parameters

message(optional)The prompt text to show the user.

Returns

The line the user typed (str).

Example

name = input("Your name: ")
print("Hello " + name)

Expected output

(After entering the name) Hello Alex

When to use?

For getting a name, number, or choice from the user in small console programs.

Common mistakes

  • ⚠️ input() always returns text; for arithmetic, convert it like yas = int(input()).

f-string

Try it yourself →

Embeds a variable/expression inside text.

Syntax

f"text {value} text"

Description

If you put f before the quote, the variable or expression you write inside the curly braces { } is automatically inserted into the text. The most readable way to combine text.

Returns

The formatted text (str).

Example

name = "Alex"
score = 95
print(f"{name} today got {score} score")
print(f"Total: {10 + 5}")

Expected output

Alex today got 95 score
Total: 15

When to use?

When combining variables with text and printing them; it saves you from fiddling with +.

Common mistakes

  • ⚠️ Forgetting the leading f: "{name}" is printed as-is, f"{name}" inserts its value.
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