Use the type() built-in 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

Note that Python doesn't have the same types as C/C++, which appears to be your question.

Answer from gregjor on Stack Overflow
🌐
W3Schools
w3schools.com › python › gloss_python_getting_data_type.asp
Python Getting Data Types
Python Variables Variable Names Assign Multiple Values Output Variables Global Variables Variable Exercises Code Challenge Python Data Types
Discussions

What's the canonical way to check for type in Python? - Stack Overflow
There is still a place for runtime ... expected type?". ... See Built-in Functions in the Python Library Reference for relevant information. For Python 2, this is a better way to check if o is a string: ... because this will also catch Unicode strings. unicode is not a subclass of str; both str and unicode are subclasses of basestring. In Python 3, basestring no longer exists since there's a strict separation of strings (str) and binary data ... More on stackoverflow.com
🌐 stackoverflow.com
How do you determine what data type user inputs (python 3)?
Use try and except for valueError https://www.pythonforbeginners.com/error-handling/python-try-and-except More on reddit.com
🌐 r/learnpython
7
5
December 16, 2018
How does Python recognize data type of a variable?
Hello Everyone. Question: How does Python recognize data type of a variable? Like if I assign a value 1 to a variable a, how does python know this is an integer? If I try to do something like this below: a = 1 b = "hello" print (a+b) Python will show me an error. More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
5
0
May 21, 2023
Type Checking in Python: How to ...
Homebrew: 7.0.0 - faster installations and upgrades, stronger sandboxing, a native macOS app, built-in vulnerability checks and an advisory database, the end of macOS 10.15 support and Intel Macs moving to Tier 3. More on reddit.com
🌐 r/programming
People also ask

How to Check if Type Is String in Python?
To check if a variable is a string in Python, you can use the isinstance() function. This function checks if an object is an instance or subclass of a specified class. For example: var = "Hello, World!" if isinstance(var, str):     print("var is a string") This code snippet checks if var is of type str and prints a confirmation message if it is.
🌐
simplilearn.com
simplilearn.com › home › resources › software development › the python type() function
The Python type() Function
What is type code in Python?
The typecode character that was used to generate the array. The internal representation of one array item's length in bytes. Add a new item with the value x to the array's end. Return a tuple (address, length) containing the current memory address and the length of the buffer used to hold the array's contents in elements.
🌐
simplilearn.com
simplilearn.com › home › resources › software development › the python type() function
The Python type() Function
What is type class in Python?
type is a metaclass, and classes are instances of it. Any new category in Python, and therefore any class in Python 3, is an instance of the type metaclass, just as any ordinary object is an instance of a class.
🌐
simplilearn.com
simplilearn.com › home › resources › software development › the python type() function
The Python type() Function
🌐
Codecademy
codecademy.com › article › what-are-python-data-types-and-how-to-check-them
What are Python Data Types and How to Check Them | Codecademy
Learn Python data types and how to check them using `type()` and `isinstance()`. Explore type conversion techniques with practical examples.
🌐
Simplilearn
simplilearn.com › home › resources › software development › the python type() function
The Python type() Function
June 10, 2026 - Python type() is a built-in function ... not have a separate typeof function. In Python, the built-in type() function is used to check the data type of a value, variable, or object....
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Digis
digiscorp.com › python-check-type-of-variable-top-3-methods-explained
Python Check Type of Variable: Top 3 Methods Explained
December 9, 2024 - The most common approaches are type() and isinstance(), while custom classes and abstract base classes provide additional options for object-oriented applications. In this guide, we explain how to check the type of a variable in Python, when ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-type-function
type() function in Python - GeeksforGeeks
Example 1: Checks the data types of different Python values to show how type() identifies built-in data types.
Published: July 29, 2026
🌐
Python documentation
docs.python.org › 3 › library › typing.html
typing — Support for type hints
2 weeks ago - return data · This behavior allows Any to be used as an escape hatch when you need to mix dynamically and statically typed code. Contrast the behavior of Any with the behavior of object. Similar to Any, every type is a subtype of object. However, unlike Any, the reverse is not true: object is not a subtype of every other type. That means when the type of a value is object, a type checker will reject almost all operations on it, and assigning it to a variable (or using it as a return value) of a more specialized type is a type error.
🌐
freeCodeCamp
freecodecamp.org › news › python-print-type-of-variable-how-to-get-var-type
Python Print Type of Variable – How to Get Var Type
February 16, 2022 - The type() function is a valuable built-in function of Python with which you can get the data type of a variable.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-check-the-type-of-an-object-in-python
How to Check the Type of an Object in Python - GeeksforGeeks
July 23, 2025 - Python offers several methods for identifying an object's type, with the most basic being the built-in type() function, which provides a quick way to check an object's type. More advanced techniques, such as the isinstance() function, offer ...
🌐
Python
docs.python.org › 3 › builtins › stdtypes.html
Built-in Types — Python 3.14.7 documentation
The following table summarizes the text and binary sequence types methods by category. Textual data in Python is handled with str objects, or strings. Strings are immutable sequences of Unicode code points.
🌐
W3Schools
w3schools.com › python › python_datatypes.asp
Python Data Types
Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these categories:
🌐
Quora
quora.com › How-can-you-check-the-type-of-a-variable-in-Python
How to check the type of a variable in Python - Quora
Answer (1 of 2): you can check the type of variable using the [code ]type()[/code] function The [code ]type()[/code] function is a built-in function in Python that returns the class type of the variable you pass as an argument. Here's an example: [code]name = "Krishna" age = 20 print(type(nam...
🌐
Reddit
reddit.com › r/learnpython › how do you determine what data type user inputs (python 3)?
r/learnpython on Reddit: How do you determine what data type user inputs (python 3)?
December 16, 2018 -

I was trying to code a program where a user inputs an integer and see if the number is even or odd.

This part was not a problem, but I am struggling to create code that determines whether the user input is int, float, or str.

I know that user input is always in string, and if I wanted to change it to integer, I just have to put int(<user input>).

But what I want to do is to see if the user has typed something other than integer; I don't want the program to error out because the user types in a float or a string.

For example, if user enters "123.sedfv", I want the program to say it's a string and loop back it to make the user re-type an integer instead of the code shutting down due to input error.

Another example: If user types in a negative number, "-1293898434.", I want it to say "even".

Also, if the user types, for example, "five", "five.", "5." I want the code to convert it to integer instead of saying string/float or giving error.

My current code:

#checks if user input is even or odd

def evenodd(num):
if num % 2 == 0:
return "The number is even."
else:
return "The number is odd."
# user inputs a number and prints if its even or odd
while True:
print(evenodd(int(input("Enter an integer: "))))

I am a total noob and have no idea where to start with this...

🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
How does Python recognize data type of a variable? - Curriculum Help - The freeCodeCamp Forum
May 21, 2023 - Hello Everyone. Question: How does Python recognize data type of a variable? Like if I assign a value 1 to a variable a, how does python know this is an integer? If I try to do something like this below: a = 1 b = "hello" print (a+b) Python will show me an error.
🌐
Real Python
realpython.com › python-type-checking
Python Type Checking (Guide) – Real Python
January 7, 2019 - In this guide, you'll look at Python type checking. Traditionally, types have been handled by the Python interpreter in a flexible but implicit way. Recent versions of Python allow you to specify explicit type hints that can be used by different tools to help you develop your code more efficiently.
🌐
Facebook
facebook.com › GirlCoderOfficial › posts › check-data-typedatatypes-pythonbasics-typechecking › 1462530155883767
Check Data Type #DataTypes #PythonBasics ...
Explore the things you love · Log in to Facebook · English (UK) · Русский · Українська · Suomi · 中文(简体) · Deutsch · العربية · More languages…
🌐
Sentry
sentry.io › sentry answers › python › determine the type of a python variable
Determine the type of a Python variable | Sentry
March 15, 2023 - We can determine a Python variable’s type using the built-in function type(). This will work for built-in types as well as our own classes.
🌐
Index.dev
index.dev › blog › check-python-variable-types
How to Check the Type of Variable in Python (+Examples)
Python gives you a clear ladder of tools. Use type() for exact class checks, isinstance() for runtime checks that respect inheritance, and type hints with built-in generics to document and constrain your code.
🌐
Learn Python
learnpython.org › en › Variables_and_Types
Variables and Types - Learn Python - Free Interactive Python Tutorial
Good news! You can save 25% off your Datacamp annual subscription with the code LEARNPYTHON23ALE25 - Click here to redeem your discount · Python is completely object oriented, and not "statically typed". You do not need to declare variables before using them, or declare their type.