# \[python\] 5.0 flottant ou entier?

**URL:** <https://www.debian-fr.org/t/python-5-0-flottant-ou-entier/75569>\
**Category:** Programmation\
**Created:** [Janvier 6, 2018, 8:02 UTC](https://www.debian-fr.org/t/python-5-0-flottant-ou-entier/75569 "2018-01-06T20:02:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![limax](https://www.debian-fr.org/user_avatar/www.debian-fr.org/limax/32/3886_2.png) [@limax](https://www.debian-fr.org/u/limax)\
**Post date:** [Janvier 6, 2018, 8:02 UTC](https://www.debian-fr.org/t/python-5-0-flottant-ou-entier/75569/1 "2018-01-06T20:02:50Z")

</div>

Bonjour  
Une petite question 5.0 est il un flottant ou un entier?

```python
In [1]: x=5.0
In [2]: type(x)
Out[2]: float
In [3]: x.is_integer()
Out[3]: True

```

J’avoue ne pas comprendre la méthode is\_integer().

---

<div class="post-metadata">

**Author:** ![anon29980398](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@anon29980398](https://www.debian-fr.org/u/anon29980398)\
**Post date:** [Janvier 6, 2018, 8:52 UTC](https://www.debian-fr.org/t/python-5-0-flottant-ou-entier/75569/2 "2018-01-06T20:52:12Z")

</div>

Bonsoir **limax**

Si la valeur assignée à la variable testée est un entier  
la méthode **float.is\_integer**  
retournera **True**

```auto
michel@debg53sw:~$ python
Python 2.7.9 (default, Jun 29 2016, 13:08:31) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x=5.0
>>> x.is_integer()
True
>>> 
>>> x=-5.0
>>> x.is_integer()
True
>>> 
>>> x=5.12345
>>> x.is_integer()
False
>>> 
michel@debg53sw:~$ 

```

---

<div class="post-metadata">

**Author:** ![limax](https://www.debian-fr.org/user_avatar/www.debian-fr.org/limax/32/3886_2.png) [@limax](https://www.debian-fr.org/u/limax)\
**Post date:** [Janvier 6, 2018, 9:30 UTC](https://www.debian-fr.org/t/python-5-0-flottant-ou-entier/75569/3 "2018-01-06T21:30:10Z")

</div>

Bonsoir

Je devrais toujours me documenter avant de poster.

> help((5.0).is\_integer)  
> Help on built-in function is\_integer:  
> is\_integer(…) method of builtins.float instance  
> Return True if the float is an integer.
