Python Data Types Explained for Beginners | AI Python Full Stack Course
Every programming language stores and processes different kinds of information, such as numbers, text, logical values, and collections of data. Python uses data types to classify these values and determine what operations can be performed on them.
In this lesson, you’ll learn about Python’s built-in data types, including integers, floating-point numbers, strings, booleans, lists, tuples, sets, and dictionaries. You’ll also explore type checking, type conversion, and real-world examples to understand when and why each data type is used.
By the end of this lesson, you’ll be able to choose the appropriate data type for different programming tasks and write more efficient, readable Python code.
Learning Objectives
After completing this lesson, you will be able to:
- Understand what data types are.
- Identify Python’s built-in data types.
- Work with numeric, text, and boolean values.
- Use lists, tuples, sets, and dictionaries.
- Check the type of a variable.
- Convert one data type into another.
- Apply the correct data type in real-world applications.
- Write optimized and readable Python code.
Topics Covered
- What are Data Types?
- Numeric Data Types
- String Data Type
- Boolean Data Type
- List
- Tuple
- Set
- Dictionary
- Type Checking
- Type Conversion
- Best Practices
Detailed Lesson Content
Introduction to Data Types
Imagine you’re developing an online shopping website. Different kinds of information need to be stored:
- Product Name → Text
- Price → Decimal Number
- Quantity → Whole Number
- Product Available → True or False
- Categories → Multiple Values
- Customer Details → Key-Value Pairs
Python uses data types to identify and organize these different kinds of data.
A data type tells Python:
- What kind of value is stored.
- How much memory should be allocated.
- What operations can be performed on that value.
Without data types, a programming language would not know whether a value represents text, a number, or a collection of items.
Numeric Data Types
Python supports three primary numeric data types.
Integer (int)
Integers are whole numbers without decimal points.
Examples:
age = 21
marks = 95
employees = 250
Integers can be positive or negative.
temperature = -10
Float (float)
A float represents decimal numbers.
price = 599.99
percentage = 92.75
pi = 3.14159
Float values are commonly used for:
- Product prices
- Measurements
- Percentages
- Scientific calculations
Complex Numbers
Python also supports complex numbers.
x = 5 + 3j
Although rarely used in web development, they are useful in scientific computing and engineering applications.
String Data Type (str)
A string stores textual information.
Strings can be enclosed using:
name = "Rahul"
city = 'Jaipur'
Examples of strings:
- Student Name
- Email Address
- Product Name
- Mobile Number
- Password
Python allows multi-line strings.
message = """
Welcome
to
Mango Engineers
"""
Strings support many useful operations.
course = "Python"
print(course.upper())
print(course.lower())
print(len(course))
Boolean Data Type (bool)
A Boolean value represents only two possible states.
True
False
Example:
is_logged_in = True
is_admin = False
Booleans are heavily used in:
- Login Systems
- Authentication
- Decision Making
- Conditions
- AI Models
List
A list stores multiple values in a single variable.
courses = ["Python","Java","React"]
Lists are:
- Ordered
- Changeable
- Allow Duplicate Values
Example:
marks = [85,90,92,95]
Accessing list elements
print(marks[0])
Adding new values
courses.append("Django")
Tuple
A tuple is similar to a list but cannot be modified.
colors = ("Red","Green","Blue")
Tuples are:
- Ordered
- Immutable
- Faster than Lists
Example use cases:
- Coordinates
- Configuration Values
- Fixed Data
Set
A set stores unique values.
languages = {"Python","Java","C++"}
Features
- No duplicate values
- Unordered
- Fast searching
Example
numbers = {1,2,3,2,1}
print(numbers)
Output
{1,2,3}
Dictionary
A dictionary stores data in key-value pairs.
Example:
student = {
"name":"Rahul",
"age":21,
"city":"Jaipur"
}
Accessing values
print(student["name"])
Dictionaries are widely used in:
- APIs
- JSON
- Databases
- AI Models
- User Profiles
Checking Data Types
Python provides the type() function to determine the data type of a variable.
age = 20
print(type(age))
Output
<class 'int'>
Examples
print(type(25))
print(type(25.5))
print(type("Python"))
print(type(True))
Type Conversion
Sometimes you need to convert one data type into another.
Integer to Float
x = 20
print(float(x))
Output
20.0
Float to Integer
price = 99.99
print(int(price))
Output
99
Integer to String
age = 22
print(str(age))
String to Integer
marks = "95"
print(int(marks))
String to Float
salary = "45000.50"
print(float(salary))
Real-World Example
Suppose you’re developing a Student Management System.
student_name = "Rahul Sharma"
age = 20
percentage = 91.75
is_placed = False
skills = ["Python","SQL","React"]
address = {
"city":"Jaipur",
"state":"Rajasthan"
}
print(student_name)
print(age)
print(percentage)
print(is_placed)
print(skills)
print(address)
This example demonstrates how multiple data types work together to represent real-world information in an application.
Best Practices
- Choose the appropriate data type for the information being stored.
- Use lists for dynamic collections.
- Use tuples for fixed data.
- Use dictionaries for structured key-value information.
- Avoid unnecessary type conversions.
- Use descriptive variable names.
- Validate data before converting types.
Key Takeaways
- Every value in Python has a data type.
- Integers store whole numbers.
- Floats store decimal values.
- Strings store text.
- Booleans represent True or False.
- Lists store ordered, mutable collections.
- Tuples store ordered, immutable collections.
- Sets store unique values.
- Dictionaries store key-value pairs.
- Use
type()to check data types. - Use
int(),float(),str(), andbool()for type conversion.



