---
title: "How do you check the data type of a variable?"  
description: "How do you check the data type of a variable?"  
author: "ICSM Computer"  
published: 2025-04-22  
updated: 2025-06-03  
canonical: https://www.mindstick.com/forum/161517/how-do-you-check-the-data-type-of-a-variable  
category: "python"  
tags: ["python-3.4", "python"]  
reading_time: 1 minute  

---

# How do you check the data type of a variable?

How do you [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) the [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) type of a [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation)?

## Replies

### Reply by ICSM Computer

In Python, you can check the data type of a variable using the built-in function `type()`.

### Example:

```python
x = 42
print(type(x))  # Output: <class 'int'>

y = "Hello"
print(type(y))  # Output: <class 'str'>

z = [1, 2, 3]
print(type(z))  # Output: <class 'list'>
```

### Additional tips:

- To check if a variable is of a specific type, use `isinstance()`:

```python
if isinstance(x, int):
    print("x is an integer")
```

- `type()` returns the exact type, while `isinstance()` supports inheritance (useful for checking subclasses).


---

Original Source: https://www.mindstick.com/forum/161517/how-do-you-check-the-data-type-of-a-variable

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
