Home Tutorials Python Tutorial Data Types
Data Types

Data Types


Definition: Data types represent the kind of value a variable holds. Python supports several basic data types such as integers, floating-point numbers, strings, and booleans.

Why: Data types are a core foundation topic because they determine what kind of operations you can perform on a piece of data (for example, you can multiply integers, but you cannot multiply strings in the same way).

Common Data Types

  • Integer (int): Whole numbers without decimals (e.g., 10, -5).
  • Float: Numbers with decimal points (e.g., 3.14, 2.0).
  • String (str): Text wrapped in quotes (e.g., "Ravi", 'Python').
  • Boolean (bool): Represents logical values: True or False.

Example

x = 10
pi = 3.14
name = "Ravi"
is_open = True

print(type(x))
print(type(pi))
print(type(name))
print(type(is_open))

Explanation

  • The type() function is used to check the data type of any variable.
  • x is identified as <class 'int'>.
  • pi is identified as <class 'float'>.
  • name is identified as <class 'str'>.
  • is_open is identified as <class 'bool'>.

Key Notes

  • Python is dynamically typed, meaning you don't have to explicitly state the type; Python figures it out for you.
  • Booleans must always start with a capital letter (True/False).
Example

🏋️ Test Yourself With Exercises

Take our quiz on Data Types to test your knowledge.

Exercise »