Python Tutorial

Introduction

Edit Template
  • Home
  • /
  • Python Data Types

Python Tutorial

Introduction

Edit Template
  • Home
  • /
  • Python Data Types

Python Data Types

Every piece of data in a Python program has a type behind it. That type tells Python how the data should behave when it’s used. Whether it’s a number, text, or a more complex structure, data types help Python process it correctly.

You don’t need to declare data types manually — Python figures it out based on the value you assign.

Numeric Types

Python offers three numeric types:

  • int – Whole numbers

  • float – Numbers with decimal points

  • complex – Numbers with real and imaginary parts

				
					a = 10         # int
b = -3.7       # float
c = 4 + 3j     # complex

print(type(a), type(b), type(c))

				
			

Text Type

Strings (str) are used for text. They are written inside quotes — single, double, or triple.

				
					language = "Python"
slogan = 'Simple Yet Powerful'
description = """Python is beginner-friendly."""

print(language.upper(), "-", slogan)

				
			

Boolean Type

Booleans have only two values: True or False. These often control decision-making.

				
					is_active = True
is_deleted = False

print("Is Active:", is_active)

				
			

Sequence Types

These hold multiple values in order. Python provides:

List: A flexible collection that you can update.

				
					groceries = ["Milk", 1.5, True, [1, 2]]
groceries[0] = "Almond Milk"
print(groceries)

				
			

Tuple: Just like a list, but you can’t change it after creating it.

				
					days = ("Monday", "Tuesday", "Wednesday")
print("Today is:", days[1])

				
			

Range: Creates a sequence of numbers with a start, stop, and step.

				
					for n in range(2, 11, 2):
    print(n, end=' ')

				
			

Mapped Type

Dictionary (dict): A collection of key-value pairs — perfect when data is labeled.

				
					student = {
    "name": "Arshyan",
    "age": 19,
    "verified": True
}
print(student["name"])

				
			

Set Type

Sets are unordered, and they automatically remove duplicate values.

				
					unique_numbers = {5, 2, 9, 2, 1}
print("Unique values:", unique_numbers)

				
			

Binary Types

Python also supports data in binary format. Useful when working with files, images, etc.

bytes

				
					msg = "Arshyan Rocks"
binary_msg = bytes(msg, "utf-8")
print(binary_msg)

				
			

bytearray :Unlike bytes, this is mutable.

				
					data = bytearray("Code", "utf-8")
data[0] = 67
print(data)

				
			

memoryview :Gives direct access to memory — useful for optimization.

				
					bdata = bytes("data", "utf-8")
view = memoryview(bdata)
print([byte for byte in view])

				
			

None Type

The None keyword is used when you want to say “nothing” — not zero, not empty, just nothing.

				
					result = None
print("Type of result is", type(result))

				
			

Summary

  • Python detects the data type automatically.

  • Use lists when you want to store and modify a collection.

  • Use tuples for fixed collections.

  • Use sets when you want only unique values.

  • Use dictionaries when you need key-value pairing.

  • Use booleans to control logic.

  • Use None when you want to reset a variable.

Scroll to Top