Python Data Types

🧱 Python Data Types

Python Data types define the kind of value stored in a variable. Python is dynamically typed, meaning you don’t need to declare a type—the interpreter detects it automatically.

Example:

x = 10 # int
name = "Raj" # string
price = 99.5 # float

🔍 How to Check Data Type

Use the type() function:

x = 10
print(type(x))

🏷 Categories of Python Data Types

CategoryData Type
Textstr (String)
Numericint, float, complex
Booleanbool
Sequencelist, tuple, range
Mappingdict
Setset, frozenset
Binarybytes, bytearray, memoryview
None TypeNoneType

📌 Built-in Data Types Explained


1️⃣ String (str)

Used for text data.

name = "Python"
print(type(name))

Strings can be in single ' ', double " ", or triple quotes """ """.


2️⃣ Numeric Types

🔹 int (Integer)

Whole numbers:

age = 25

🔹 float (Decimal Numbers)

price = 99.99

🔹 complex (Numbers with imaginary part)

z = 3 + 5j

3️⃣ Boolean (bool)

Stores True or False.

isActive = True
print(type(isActive))

4️⃣ List (list)

Ordered, changeable, allows duplicates.

fruits = ["apple", "banana", "orange"]
print(type(fruits))

5️⃣ Tuple (tuple)

Ordered, unchangeable, allows duplicates.

colors = ("red", "green", "blue")

6️⃣ Range (range)

Used in loops.

numbers = range(5)
print(list(numbers))

7️⃣ Dictionary (dict)

Stores data in key: value pairs.

student = {"name": "Vipul", "age": 25}

8️⃣ Set (set)

Unordered, no duplicate items.

nums = {10, 20, 30}

9️⃣ Frozen Set (frozenset)

Immutable (unchangeable) version of set.

fs = frozenset({1, 2, 3})

🔟 Binary Types

TypeDescription
bytesImmutable binary data
bytearrayMutable binary data
memoryviewAccess memory of binary objects

Example:

data = bytes([10, 20, 30])
print(type(data))

1️⃣1️⃣ None Type (NoneType)

Represents empty or no value.

x = None
print(type(x))

🧪 Example Program Using All Types

name = "Vipul"
age = 25
height = 5.11
is_student = False
skills = ["Python", "SQL"]
details = {"city": "Surat", "country": "India"}
print(type(name))
print(type(age))
print(type(height))
print(type(is_student))
print(type(skills))
print(type(details))

🏁 Summary Table

Data TypeExample
str"Hello"
int10
float10.5
boolTrue
list[1,2,3]
tuple(1,2,3)
dict{"a":1}
set{1,2,3}
complex3+5j
NoneTypeNone

🧠 Practice Tasks

Try these:

  1. Create a variable of each data type and print its type.

  2. Convert integer to float and float to integer.

  3. Create a list and modify one value.

  4. Create a tuple and try modifying it — notice the error.

You may also like...