2

Скажите пожалуйста (с примером)

1
  • isinstance(число, float)
    – andreymal
    17 янв 2019 в 11:55

1 ответ 1

5

Создание условий с проверкой типа float:

type(2.3) == float
# True

type(2.3) == float or type(2.3) == decimal.Decimal
# True

type(2.3) is float
# True

type(2.3) is not int
# True

isinstance(2.3, float)
# True

isinstance(2.3, (float, decimal.Decimal))
# True

2.3.is_integer()
# False
1
  • is вместо == более питоничиское. Иначе красивый ответ.
    – MarianD
    17 янв 2019 в 23:24

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.