-
Hajipur, Bihar, 844101
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.
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 |
int
: Whole numbers (e.g., 5, -10, 100)
float
: Decimal numbers (e.g., 3.14, -0.99)
complex
: Complex numbers (e.g., 2 + 3j)
str
: A sequence of Unicode characters (e.g., "hello", 'Python')
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)
dict
: Key-value pairs
Example: {"name": "Alice", "age": 25}
bool
: Only two values — True
or False
Often used in comparisons and conditions.
set
: Unordered, no duplicates
Example: {1, 2, 3}
frozenset
: Like set, but immutable
Used for binary data:
bytes
bytearray
memoryview
NoneType
: Represents a null value
Example: x = None
Use type()
to check the data type of a variable.
x = 10
print(type(x)) # Output: <class 'int'>
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 |
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()
.
Q1: What is the data type of "Hello" in Python?
Q2: Which data type is used to store decimal values?
Q3: What is the type of True in Python?
Q4: Which of the following allows duplicate values and is changeable?
Q5: What type is returned by the type() function?
Q6: What type of data is stored in a dictionary?
Q7: Which of these is immutable?
Q8: What does the None value represent in Python?
Q9: Which data type is used to store a large collection of unique values?
Q10: Which of these types is used for binary data?