Python Numbers

Python · Variables & Data Types

Theory

Python has three numeric types. int holds whole numbers of any size; there is no overflow, so 2 ** 100 is computed exactly. float holds decimal numbers using 64-bit binary floating point, which gives about 15 to 17 significant digits but cannot store most decimals exactly, so 0.1 + 0.2 shows 0.30000000000000004. complex holds numbers like 3+4j for scientific work.

Mixing types promotes the result: int with float gives a float, so 19.99 * 3 is 59.97. The / operator always returns a float (10 / 2 is 5.0), while // performs floor division, rounding down toward negative infinity, so -7 // 2 is -4, not -3. Underscores can make big literals readable: 1_000_000. For money where every paisa matters, the decimal module avoids binary rounding errors.

Why we use it

Numbers power every calculation in analysis: totals, averages, growth rates and percentages. Knowing how int and float behave stops subtle bugs such as an unexpected .0, a float equality check that fails, or a negative floor division that rounds the wrong way.

When to use it

Use int for counts and IDs, float for measurements and ratios, and decimal.Decimal when exact decimal money arithmetic is required. Never compare floats with ==; use round() or math.isclose() instead.

How it works

  1. Python evaluates price * quantity
  2. Are both operands int? Yes: Result is an int (except with /, which gives a float). No: Promote to float and compute.
  3. Is the operator /? Yes: Return a float even if it divides evenly. No: Apply the operator normally.
  4. Store the result as a new number object
  5. Output: 59.97

Syntax

x = 10      # int
y = 10.5    # float

Example

price = 19.99
quantity = 3
total = price * quantity

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic