Python DataTypes


In Python, everything is an object, and every object has a data type.
A data type defines what kind of value a variable can hold and how it can be used.

Python automatically assigns the correct data type when you assign a value to a variable.


🧱 Built-in Data Types in Python

Category Data Types
Text Type str
Numeric Types int, float, complex
Sequence Types list, tuple, range
Mapping Type dict
Set Types set, frozenset
Boolean Type bool
Binary Types bytes, bytearray, memoryview
None Type NoneType

🔢 Numeric Data Types

  • int: Whole numbers (e.g., 5, -10, 100)

  • float: Decimal numbers (e.g., 3.14, -0.99)

  • complex: Complex numbers (e.g., 2 + 3j)


🔤 Text Type

  • str: A sequence of Unicode characters (e.g., "hello", 'Python')


📚 Sequence Data Types

  • list: Ordered, changeable, allows duplicates
    Example: [1, 2, 3]

  • tuple: Ordered, unchangeable, allows duplicates
    Example: (1, 2, 3)

  • range: Used for looping a sequence of numbers
    Example: range(5)


🗺️ Mapping Type

  • dict: Key-value pairs
    Example: {"name": "Alice", "age": 25}


🔘 Boolean Type

  • bool: Only two values — True or False
    Often used in comparisons and conditions.


🔁 Set Types

  • set: Unordered, no duplicates
    Example: {1, 2, 3}

  • frozenset: Like set, but immutable


🧊 Binary Types

Used for binary data:

  • bytes

  • bytearray

  • memoryview


🚫 None Type

  • NoneType: Represents a null value
    Example: x = None


🔍 Checking Data Type

Use type() to check the data type of a variable.

x = 10
print(type(x))  # Output: <class 'int'>

✅ Summary Table

Type Example Value Type Name
Text "Hello" str
Integer 10 int
Float 3.14 float
Boolean True bool
List [1, 2, 3] list
Tuple (1, 2, 3) tuple
Dictionary {"a": 1} dict
Set {1, 2, 3} set
None None NoneType

Practice Questions

Q1. Write a Python program to create a variable with your name and check its type using the type() function.

Q2. Write a Python program to assign a floating-point number to a variable and display its type.

Q3. Write a Python program to create a list of 5 fruits and print the list.

Q4. Write a Python program to create a tuple of 3 colors and print it.

Q5. Write a Python program to define a dictionary containing your name and age, then print it.

Q6. Write a Python program to create a set with repeated values and observe how duplicates are handled.

Q7. Write a Python program to check the type of a boolean value stored in a variable.

Q8. Write a Python program to create a variable with a complex number and print it.

Q9. Write a Python program to assign None to a variable and check its type using type().

Q10. Write a Python program to create a range of numbers from 1 to 10 and convert it into a list using list().


Python DataTypes Quiz

Q1: What is the data type of "Hello" in Python?

A. int
B. bool
C. str
D. float

Q2: Which data type is used to store decimal values?

A. int
B. bool
C. float
D. str

Q3: What is the type of True in Python?

A. int
B. str
C. bool
D. complex

Q4: Which of the following allows duplicate values and is changeable?

A. set
B. tuple
C. list
D. frozenset

Q5: What type is returned by the type() function?

A. Data
B. Variable
C. Class name
D. Function

Q6: What type of data is stored in a dictionary?

A. Only strings
B. Only numbers
C. Key-value pairs
D. Boolean values only

Q7: Which of these is immutable?

A. list
B. set
C. tuple
D. bytearray

Q8: What does the None value represent in Python?

A. Zero
B. Empty string
C. Null or no value
D. False

Q9: Which data type is used to store a large collection of unique values?

A. list
B. tuple
C. set
D. dict

Q10: Which of these types is used for binary data?

A. str
B. bool
C. bytes
D. list

Go Back Top