Python Tutoring Online
 Home            

Python Data Types – Complete Guide for Beginners with Examples

Python data types define the kind of value that a variable contains. A data type tells Python what a value represents and what operations can be performed with that value.

For example, an integer can be used for counting and mathematical calculations, a string can store text, a Boolean can represent a true-or-false condition, and a list can store multiple values. Understanding Python data types is one of the most important foundations for learning Python programming.

Python is a dynamically typed language. This means that you do not normally have to declare the data type of a variable before using it. Python determines the type automatically from the value assigned to the variable.

For example, Python automatically recognizes 25 as an integer, 3.14 as a floating-point number and "Python" as a string.

Python
age = 25
price = 19.99
name = "Alice"
is_student = True

print(type(age))
print(type(price))
print(type(name))
print(type(is_student))

Output


<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>

Python provides several built-in data types that are used to represent numbers, text, Boolean values, collections and other kinds of data.

What Are Data Types in Python?

A data type specifies the kind of data represented by a value. Data types are important because different types support different operations.

For example, Python treats these two values differently:


10
"10"

The first value is an integer, while the second value is a string. Although they look similar, Python does not treat them as the same type.

Python
number = 10
text = "10"

print(type(number))
print(type(text))

Output


<class 'int'>
<class 'str'>

Python Built-in Data Types

Python has several important built-in data types. They can be grouped into categories according to the kind of data they represent.

Category Data Type Example
Numeric int 25
Numeric float 3.14
Numeric complex 2 + 3j
Text str "Python"
Boolean bool True
Sequence list [1, 2, 3]
Sequence tuple (1, 2, 3)
Sequence range range(5)
Mapping dict {"name": "Alice"}
Set set {1, 2, 3}
Set frozenset frozenset({1, 2, 3})
Binary bytes b"Python"
Binary bytearray bytearray(5)
Binary memoryview memoryview(data)
Special NoneType None

For beginners, the most important types to learn first are int, float, str, bool, list, tuple, set and dict. These types appear frequently in Python programs.

Checking the Data Type of a Variable

Python provides the built-in type() function for checking the data type of a value or variable.

Python
x = 10

print(type(x))

Output


<class 'int'>

The output shows that x contains an integer.

You can also check the type of an expression:

Python
result = 10 / 2

print(result)
print(type(result))

Output


5.0
<class 'float'>

Notice that normal division using / produces a floating-point result, even when both operands are integers.

Integer Data Type in Python (int)

The integer data type, written as int, represents whole numbers. Integers can be positive, negative or zero.

Examples include:

Python integers are commonly used for counting, indexing, ages, quantities, scores and mathematical calculations.

Example: Integer Variables

Python
age = 25
year = 2026
temperature = -5
students = 30

print(age)
print(year)
print(temperature)
print(students)

Output


25
2026
-5
30

Example: Integer Calculations

Python
a = 10
b = 5

total = a + b

print(total)

Output


15

Integers can be used with arithmetic operators such as +, -, *, //, % and **.

Float Data Type in Python (float)

The float data type represents floating-point numbers, which commonly contain decimal values.

Examples include:

Floats are commonly used for measurements, percentages, scientific calculations, averages and other values that may contain decimal fractions.

Example: Float Values

Python
price = 19.99
height = 5.8
temperature = -2.5

print(price)
print(height)
print(temperature)

Output


19.99
5.8
-2.5

Example: Float Calculation

Python
a = 5.5
b = 2.5

result = a + b

print(result)

Output


8.0

Complex Number Data Type in Python

Python also supports complex numbers. A complex number contains a real part and an imaginary part.

The imaginary part uses the letter j in Python.

Python
number = 2 + 3j

print(number)
print(type(number))

Output


(2+3j)
<class 'complex'>

Complex numbers are mainly used in scientific computing, engineering, mathematics and specialized numerical applications. Most beginners do not need complex numbers immediately, but it is useful to know that Python supports them as a built-in numeric type.

String Data Type in Python (str)

The string data type, written as str, represents text. Strings can contain letters, numbers, spaces and special characters.

Python strings can be written using single quotes, double quotes or triple quotes for longer strings.

Python
name = "Alice"
course = "Python Programming"
city = "London"

print(name)
print(course)
print(city)

Output


Alice
Python Programming
London

Numbers Stored as Strings

A number written inside quotation marks is a string rather than a numeric value.

Python
number = "100"

print(number)
print(type(number))

Output


100
<class 'str'>

This distinction is important when working with user input because input() returns a string by default.

String Concatenation

Strings can be joined together using the + operator. This process is called string concatenation.

Python
first_name = "Alice"
last_name = "Smith"

full_name = first_name + " " + last_name

print(full_name)

Output


Alice Smith

String Length

The built-in len() function can be used to find the number of characters in a string.

Python
message = "Python"

print(len(message))

Output


6

Boolean Data Type in Python (bool)

The Boolean data type, written as bool, represents one of two logical values: True or False.

Boolean values are particularly important for conditions, comparisons, decision-making and program control.

Python
is_student = True
is_logged_in = False

print(is_student)
print(is_logged_in)

Output


True
False

Boolean Values from Comparisons

Comparison expressions produce Boolean results.

Python
x = 10
y = 5

print(x > y)
print(x == y)
print(x < y)

Output


True
False
False

The expression x > y is True because 10 is greater than 5.

Boolean Values in if Statements

Boolean expressions are frequently used with if statements.

Python
age = 20

if age >= 18:
    print("Adult")

Output


Adult

List Data Type in Python (list)

A list is a collection used to store multiple values in a single variable. Lists are ordered and mutable, which means their contents can be changed after the list is created.

Lists can contain numbers, strings, Boolean values or even other collections.

Python
fruits = ["apple", "banana", "cherry"]

print(fruits)

Output


['apple', 'banana', 'cherry']

Accessing Items in a Python List

List items can be accessed using an index. Python uses zero-based indexing, so the first item has index 0.

Python
fruits = ["apple", "banana", "cherry"]

print(fruits[0])
print(fruits[1])

Output


apple
banana

Changing a List Item

Because lists are mutable, an existing item can be changed.

Python
fruits = ["apple", "banana", "cherry"]

fruits[1] = "orange"

print(fruits)

Output


['apple', 'orange', 'cherry']

Lists are widely used when a program needs to store and process a collection of values.

Tuple Data Type in Python (tuple)

A tuple is an ordered collection of values. Unlike a list, a tuple is immutable, which means its items cannot normally be changed after the tuple has been created.

Python
coordinates = (10, 20)

print(coordinates)
print(type(coordinates))

Output


(10, 20)
<class 'tuple'>

Tuples are useful when you want to group related values together and do not want those values to be modified.

Accessing Tuple Items

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

print(colors[0])
print(colors[2])

Output


red
blue

Set Data Type in Python (set)

A set is a collection of unique values. Sets are particularly useful when duplicate values need to be removed or when you need to perform mathematical set operations.

Python
numbers = {1, 2, 3, 3, 4}

print(numbers)

Output


{1, 2, 3, 4}

The duplicate value 3 appears only once because a set stores unique elements.

Checking Membership in a Set

Python
numbers = {10, 20, 30}

print(20 in numbers)
print(50 in numbers)

Output


True
False

Sets are useful when membership testing and uniqueness are important.

Dictionary Data Type in Python (dict)

A dictionary, written as dict, stores data as key-value pairs. Dictionaries are useful when information needs to be associated with meaningful keys.

Python
student = {
    "name": "Alice",
    "age": 20,
    "score": 85
}

print(student)

Output


{'name': 'Alice', 'age': 20, 'score': 85}

Accessing Dictionary Values

Dictionary values can be accessed using their keys.

Python
student = {
    "name": "Alice",
    "age": 20
}

print(student["name"])
print(student["age"])

Output


Alice
20

Dictionaries are commonly used for structured information such as student records, customer information, product details and configuration settings.

Range Data Type in Python (range)

The range type represents a sequence of numbers and is commonly used with for loops.

Python
numbers = range(5)

for number in numbers:
    print(number)

Output


0
1
2
3
4

The expression range(5) produces numbers starting at zero and stopping before five.

NoneType and the None Value in Python

Python has a special value called None. It represents the absence of a value or the lack of a meaningful result.

Python
result = None

print(result)
print(type(result))

Output


None
<class 'NoneType'>

None is commonly used when a variable has no value yet, when a function does not return a meaningful result, or when a program needs to represent a missing value.

Bytes Data Type in Python (bytes)

The bytes data type represents a sequence of bytes. It is commonly used when working with binary data, files, network communication and certain encoding operations.

Python
data = b"Python"

print(data)
print(type(data))

Output


b'Python'
<class 'bytes'>

Most beginners will work with strings much more frequently than bytes, but the bytes type becomes important when working with binary data and network applications.

Mutable and Immutable Python Data Types

Another important concept when learning Python data types is the difference between mutable and immutable objects.

A mutable object can be changed after it is created. An immutable object cannot be changed after creation.

Data Type Generally Mutable?
list Yes
dict Yes
set Yes
tuple No
str No
int No
float No
bool No

Example of a Mutable List

Python
numbers = [1, 2, 3]

numbers[0] = 100

print(numbers)

Output


[100, 2, 3]

The list can be changed after it is created, so lists are mutable.

Example of an Immutable String

Strings cannot be changed in place. Operations on strings create new string values.

Python
name = "Alice"

name = name + " Smith"

print(name)

Output


Alice Smith

The original string is not modified in place. A new string value is assigned to name.

Python Type Conversion

Type conversion, also called type casting, means converting a value from one data type to another.

Python provides several built-in functions for converting values, including int(), float(), str() and bool().

Converting String to Integer

Python
number = "25"

number = int(number)

print(number)
print(type(number))

Output


25
<class 'int'>

Converting String to Float

Python
price = "19.99"

price = float(price)

print(price)
print(type(price))

Output


19.99
<class 'float'>

Converting Number to String

Python
age = 25

text = str(age)

print(text)
print(type(text))

Output


25
<class 'str'>

Python Data Types and the input() Function

The input() function is especially important when learning about Python data types because it always returns the user's input as a string.

Python
age = input("Enter your age: ")

print(type(age))

Output Example


Enter your age: 20
<class 'str'>

If the value is needed as an integer, it must be converted.

Python
age = int(input("Enter your age: "))

print(type(age))

Output Example


Enter your age: 20
<class 'int'>

Why Python Data Types Matter

Python data types determine what operations can be performed on values. Using the correct data type is therefore important when designing a program.

For example, mathematical calculations normally require numeric types, while names and messages are represented using strings.

Python
price = 100
quantity = 3

total = price * quantity

print(total)

Output


300

Here, price and quantity are integers, allowing Python to perform numerical multiplication.

Python Data Type Errors

Using incompatible data types can produce errors. A common beginner mistake is trying to add a number to a string.

Python
age = 20
message = "Age: "

print(message + age)

This produces a TypeError because Python cannot directly concatenate a string and an integer using the + operator.

One solution is to convert the number into a string:

Python
age = 20
message = "Age: "

print(message + str(age))

Output


Age: 20

Choosing the Right Python Data Type

Choosing an appropriate data type makes Python programs easier to design, understand and maintain.

If you need to store... Use
A whole number int
A decimal number float
Text str
True or false bool
An ordered collection that can change list
An ordered collection that should not change tuple
Unique values set
Key-value information dict
A missing or absent value None

Example: Using Different Python Data Types Together

A real Python program will often use several data types at the same time. For example, a student record can contain a name, age, score and enrollment status.

Python
name = "Alice"
age = 20
score = 87.5
is_student = True

print("Name:", name)
print("Age:", age)
print("Score:", score)
print("Student:", is_student)

Output


Name: Alice
Age: 20
Score: 87.5
Student: True

This example uses four different Python data types: str, int, float and bool.

Common Python Data Type Mistakes

Python Data Types and Variables

Python variables do not have to be permanently associated with one data type. A variable can refer to an object of one type and later be assigned an object of another type.

Python
value = 10

print(type(value))

value = "Python"

print(type(value))

Output


<class 'int'>
<class 'str'>

This behavior is one of the characteristics of Python's dynamic typing.

Frequently Asked Questions About Python Data Types

What are data types in Python?

Python data types define the kind of value represented by an object. Common Python data types include int, float, str, bool, list, tuple, set and dict.

What are the four basic data types in Python?

For beginners, four fundamental Python data types are integers (int), floating-point numbers (float), strings (str) and Boolean values (bool). Python also provides many other built-in data types.

How do I check the data type of a variable in Python?

Use the built-in type() function.


x = 10
print(type(x))

What is the difference between int and float in Python?

An int represents a whole number such as 10, while a float represents a floating-point number such as 10.5.

What is the difference between a string and an integer?

A string represents text and is written inside quotation marks, while an integer represents a whole number.


number = 10
text = "10"

The first value is an int and the second is a str.

What data type does input() return?

The input() function returns a string. If you need a number, convert the result using int() or float().

What is None in Python?

None is a special Python value used to represent the absence of a value or a missing result. Its data type is NoneType.

What is the difference between a list and a tuple?

Both lists and tuples are ordered collections. A list is mutable, so its contents can be changed. A tuple is immutable, so its contents cannot normally be changed after it has been created.

What is a dictionary in Python?

A dictionary stores information as key-value pairs. Dictionaries are useful when values need to be associated with meaningful keys, such as a student's name, age and score.

What is a set in Python?

A set is a collection of unique values. It is useful when duplicate values need to be removed or when membership and set operations are required.

Summary of Python Data Types

Python data types determine the kind of values used by a Python program. Python automatically determines the type of an object when a value is assigned, making Python a dynamically typed language.

Data Type Purpose Example
int Whole numbers 25
float Decimal numbers 3.14
complex Complex numbers 2 + 3j
str Text "Python"
bool True or false values True
list Ordered mutable collection [1, 2, 3]
tuple Ordered immutable collection (1, 2, 3)
set Collection of unique values {1, 2, 3}
dict Key-value collection {"name": "Alice"}
range Sequence of numbers range(5)
NoneType Represents no value None
bytes Binary data b"Python"

Learning how Python data types work is essential before moving on to more advanced topics such as lists, dictionaries, functions, loops, object-oriented programming and data processing.

Related Python Tutorials

Continue learning Python with these related tutorials:

Need Help Learning Python?

Having difficulty understanding Python data types, variables, operators or other Python fundamentals? An experienced online Python tutor can help you learn programming concepts through clear explanations and practical coding examples.

One-to-one Python tutoring provides guided coding practice and personalized help with Python fundamentals, assignments, projects and programming problems.

Get Python Tutoring Help




Stuck Learning Python?

Struggling with Python syntax, assignments or debugging errors? Learning alone can be frustrating.

Get 1-on-1 Python tutoring and learn faster with clear explanations, real examples and live help.

    Get Python Tutoring

PythonTutor.net

Home    Tutorial     Online Live Trainings    Contact Us           © 2026 All rights reserved by www.PythonTutor.net