Nearby lessons

16 of 159

Python - float Data Type

📌 What You Will Learn
  • Define the float data type and the values it stores
  • Write float values in scientific notation using e or E
  • Identify why binary, octal, and hexadecimal float literals are invalid
  • Compare int and float data types
  • Use the type() function to check whether a value is a float

Introduction

The float data type is used to store floating-point numbers (decimal numbers).

A float value always contains a decimal point.

Python supports both positive and negative decimal values.

Example

Loading editor…

Floating-Point Numbers

Float values represent numbers with a decimal point.

Some examples are:

Loading editor…

Scientific Notation (Exponential Form)

Python also allows float values to be written in scientific notation.

You can use either e or E.

Syntax:

numberePower

or

numberEPower

Example of Scientific Notation

Loading editor…

Explanation

The value 1.2e3 means:

1.2 × 10³

So the result is 1200.0.

More Examples

Loading editor…

Advantages of Scientific Notation

  • Represents very large numbers easily.
  • Makes code easier to read.
  • Useful in scientific calculations.
  • Commonly used in engineering and data science.

Example

Loading editor…

Float Values Support Only Decimal Form

Unlike integers, float values can only be written in decimal form.

Float values cannot be represented using binary, octal, or hexadecimal literals.

Invalid Binary Float

Loading editor…

Invalid Octal Float

Loading editor…

Invalid Hexadecimal Float

Loading editor…

Valid Float Examples

Loading editor…

Checking the Data Type

The type() function is used to check the data type of a value.

Loading editor…

Difference Between int and float

int float
Stores whole numbers. Stores decimal numbers.
No decimal point. Contains a decimal point.
Example: 10 Example: 10.5

Example

Loading editor…

Important Points

  • The float data type stores decimal numbers.
  • Float values are immutable.
  • Scientific notation is supported.
  • Both e and E can be used in scientific notation.
  • Binary, octal, and hexadecimal float literals are not allowed.

Key Points

  • The float data type represents decimal numbers.
  • Float values always contain a decimal point.
  • Scientific notation can be used for very large or very small values.
  • Use type() to check whether a value is a float.
  • Float values support only decimal representation.

Quick Summary

Feature Description
Data Typefloat
PurposeStores decimal numbers
Example10.5
Scientific NotationSupported
Binary FloatNot Allowed
Octal FloatNot Allowed
Hexadecimal FloatNot Allowed
MutableNo (Immutable)
📝 Key Takeaways
  • The float data type stores decimal numbers that contain a decimal point
  • Scientific notation uses e or E, for example 1.2e3 equals 1200.0
  • Float values support only decimal representation
  • Binary, octal, and hexadecimal float literals are not allowed in Python
  • int stores whole numbers, while float stores decimal numbers

🧠 Test Your Knowledge

8 Questions
Progress: 0 / 8

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.