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
int() / float()str()type() / isinstance()bool() / True-False
Python›REFERENCE›Type & Conversion
🔄

Type & Conversion

Converting between data types and type checking.

CommandDescription
int() / float()Converts text/a number to an integer or float.
str()Converts any value to text.
type() / isinstance()Finds/checks the type of a value.
bool() / True-FalseThe truth value (True/False).

int() / float()

Try it yourself →

Converts text/a number to an integer or float.

Syntax

int(value) · float(value)

Description

int() converts to an integer, float() to a float. It's essential for turning input() text into a number. Text that can't be converted raises an error.

Returns

The converted number.

Example

print(int("42") + 8)
print(float("3.5") * 2)
print(int(9.9))

Expected output

50
7.0
9

When to use?

Taking text coming from the user/a file into a calculation.

Common mistakes

  • ⚠️ int("3.5") raises an error; use float("3.5") first, then int().
  • ⚠️ int() cuts off the decimal downward; it doesn't round.

str()

Try it yourself →

Converts any value to text.

Syntax

str(value)

Description

Converts values like numbers and lists to text. Required before combining with text (or use an f-string).

Returns

The text (str).

Example

age = 36
print("Age: " + str(age))

Expected output

Age: 36

When to use?

Combining a number with text, writing to a file, printing formatted to the screen.

Common mistakes

  • ⚠️ "Age: " + age causes an error (text + number is not allowed); use str(age) or f-string.

type() / isinstance()

Try it yourself →

Finds/checks the type of a value.

Syntax

type(value) · isinstance(value, type)

Description

type() gives the value's type. isinstance() returns True/False to the question 'is this value of that type?' (preferred for checking).

Example

print(type(5))
print(isinstance("abc", str))

Expected output

<class 'int'>
True

When to use?

Debugging, verifying whether incoming data is of the expected type.

bool() / True-False

Try it yourself →

The truth value (True/False).

Syntax

bool(value)

Description

bool() converts a value to its logical truth. 0, empty text and an empty list are False; everything else is True. Used automatically in conditions.

Returns

True or False.

Example

print(bool(0))
print(bool("text"))
print(bool([]))

Expected output

False
True
False

When to use?

'Is it empty or full?' check: if items: ... (runs if items is not empty).

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