Skip to content

Python Journey

My Coding Blog

Menu
  • Links
Menu

Python>>Data Type:Float

Posted on August 23, 2022August 23, 2022 by coden00b
Floating point number is real numbers with decimal point (.)or fractional part. It can be positive or negative.
Example:
5678.90
-2.88
0.99
>>> z = -1.234
>>> type(z)
<class ‘float’>
Let’s do arithmetic:
>>> x = 8+8.1
>>> print (x)
16.1
>>> print (type(x))
<class ‘float’>

Some key notes:

1. numbers separated with underscore can consider a valid float as long has decimal point

>>> x = 66_77_88.3_21
>>> type (x)
<class ‘float’>
2. real numbersĀ  with a fractional part represented by scientific notation e or E, or those floating numbers that exceeded the maximum size (1.8 * 10^308), it will be referred as “infinity” or “inf”
>>> 1.8e308
inf
>>> x = 1.8e308
>>> print (x)
inf
>>> type (x)
<class ‘float’>
>>> 0.4e9
400000000.0
>>> x = 0.4e9
>>> type (x)
<class ‘float’>
3. there’s a function float() to convert string into float class.
>>> x = 100
>>> float (x)
100.0

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • The Zen of Python
  • Python>>String Interpolation and Formatting
  • Python>>String Methods
  • Python>>String Concatenation
  • Python>>Strings: Indexing and Slicing

Recent Comments

No comments to show.

Archives

  • January 2023
  • August 2022

Categories

  • Blog
  • Data Types