Skip to content

Instantly share code, notes, and snippets.

@pointofpresence
Last active March 31, 2024 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pointofpresence/e3b1dd3776b6def807e21d9d86f8d1a7 to your computer and use it in GitHub Desktop.
Save pointofpresence/e3b1dd3776b6def807e21d9d86f8d1a7 to your computer and use it in GitHub Desktop.
Python: Проверка типа переменной
# Use the type() builtin function:
i = 123
type(i)
# <type 'int'>
type(i) is int
# True
i = 123.456
type(i)
# <type 'float'>
type(i) is float
# True
# To check if a variable is of a given type, use isinstance:
i = 123
isinstance(i, int)
# True
isinstance(i, (float, str, set, dict))
# False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment