1

These are the main built-in data types that I know in Python:

  • Numbers
  • Strings
  • Lists
  • Tuples
  • Dictionaries
  • Boolean
  • Sets

My question is, are integers and float numbers considered to be the same data type? Or are they two separate built-in data types?

Thanks!

2
  • What documentation did you consult to arrive at this list? What makes you suspect what it says? Commented Dec 11, 2016 at 19:36
  • @Norman, I have added a response to your question, and I really hope it helps to clarify your doubts. Commented Aug 4, 2018 at 20:05

2 Answers 2

2

Quoting the python library reference:

There are four distinct numeric types: plain integers, long integers, floating point numbers, and complex numbers. In addition, Booleans are a subtype of plain integers. Plain integers (also just called integers) are implemented using long in C, which gives them at least 32 bits of precision. Long integers have unlimited precision. Floating point numbers are implemented using double in C. All bets on their precision are off unless you happen to know the machine you are working with.

Sign up to request clarification or add additional context in comments.

1 Comment

Since Python3 there are only three distinct numeric types: docs.python.org/3.6/library/…
1

According to the Python documentation:

The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions.

Numeric Types: int, float, complex

Sequence Types: list, tuple, range

Text Sequence Type: str

Binary Sequence Types: bytes, bytearray, memoryview

Set Types: set, frozenset

Mapping Types:dict

Other Built-in Types:

Modules, Classes and Class Instances, Functions, Methods, Code Objects, Type Objects, the Null Object (None), the Ellipsis Object, the NotImplemented Object, Boolean Values (True and False), Internal Objects.

Answering your question:

Are integers and float numbers considered to be the same data type?

There are three distinct numeric types: integers, floating point numbers, and complex numbers. Floating point numbers are usually implemented using double in C.

Probably you are a bit confused because mathematically speaking any number of type int and any number of type float belong to the set of the real numbers. The numbers module defines a hierarchy of numeric abstract base classes: Number, Complex, Real, Rational, and Integral. However, none of the types defined in this module can be instantiated.

You can use these classes to check if a specific number is an instance of them:

In[1]: import numbers

In [2]: isinstance(10, numbers.Integral)
Out[2]: True

In [3]: isinstance(10.5, numbers.Integral)
Out[3]: False

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.