Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
A data type tells Python what kind of value we are working with.
For example:
These variables contain different kinds of data:
Python needs to know the type of a value because different types support different operations.
For example:
makes sense because these are numbers.
But:
also works because both values are strings.
Python is dynamically typed, which means you normally do not have to declare the data type before creating a variable.
For example, you can simply write:
Python understands that 25 is an integer.
Think about organizing items in a kitchen.
You might have:
Different containers are useful for different purposes.
Python data types work in a similar way.
For beginners, these are the most important built-in types to learn:
| Data Type | Example | Used For |
|---|---|---|
int | 25 | Whole numbers |
float | 99.99 | Decimal numbers |
complex | 3 + 2j | Complex numbers |
bool | True | True/False values |
str | "Hello" | Text |
NoneType | None | No value / absence of value |
list | [1, 2, 3] | Ordered, changeable collection |
tuple | (1, 2, 3) | Ordered, unchangeable collection |
set | {1, 2, 3} | Unique values |
dict | {"name": "Sumit"} | Key-value data |
You don't need to memorize everything immediately.
We will learn each type step by step.
int — IntegerAn int stores whole numbers.
Examples:
You can perform mathematical operations with integers:
Notice that / produces a decimal value in Python.
float — Decimal NumbersA float stores numbers that contain a decimal part.
Examples:
Example:
Use float when you need decimal values.
str — TextA str stores text.
Strings are written inside quotes.
You can combine strings:
Strings can contain:
Example:
bool — True or FalseA Boolean value represents one of two possibilities:
Example:
Boolean values are commonly used when making decisions.
For example:
We will use Boolean values extensively when we learn if statements.
None — No ValueNone represents the absence of a value.
Example:
This can mean:
Another example:
This can mean:
None is different from:
and:
They mean different things.
list — Ordered and Changeable CollectionA list stores multiple values in one variable.
Example:
A list:
Example:
Because a list can be changed, it is called mutable.
tuple — Ordered and Unchangeable CollectionA tuple also stores multiple values.
Example:
A tuple:
For example:
You cannot do:
Python will raise a TypeError.
A tuple is called immutable because its contents cannot be changed in-place.
set — Unique ValuesA set stores unique values.
Example:
The duplicate "Python" is removed.
The result contains only unique values.
A set is useful when you care about uniqueness.
For example:
You don't need to manually remove duplicates.
Sets do not provide normal list-style indexing.
For example, this is not how you should access set elements:
A set is mainly used for unique values and set operations.
dict — Key-Value PairsA dictionary stores information using:
Example:
Here:
You can access a value using its key:
Dictionaries are extremely useful for storing structured information.
| Type | Ordered | Changeable | Duplicates |
|---|---|---|---|
list | Yes | Yes | Yes |
tuple | Yes | No | Yes |
set | No | Yes | No |
dict | Yes* | Yes | Keys must be unique |
Mutability means whether an object can be changed after it has been created.
A mutable object can be changed.
Examples:
Example:
The same list has been modified.
An immutable object cannot be changed after it has been created.
Common immutable types include:
Example:
Strings cannot be modified in-place.
Instead, when you create a new string value, Python uses a new string object.
For beginners, remember:
Output:
The list changed.
Output:
Here, Python creates the new string value rather than changing the original string in-place.
Python provides the type() function.
Example:
This is one of the most useful tools for beginners.
Whenever you're unsure about a value's type, try:
type() with Multiple ValuesLet's inspect several values:
Notice:
returns:
isinstance()Another useful function is isinstance().
It checks whether a value belongs to a particular type.
Example:
Output:
Another example:
Output:
boolPython's bool type is related to int.
For example:
Output:
Also:
Output:
This happens because bool is a subclass of int in Python.
You may occasionally see Boolean values behaving like 1 and 0 in calculations:
Output:
You don't need to use this behavior in normal programs.
For now, simply remember:
True and False are Boolean values used for logical decisions.Different situations require different types.
Use str:
Use int:
Use float:
Use bool:
Use list:
Use tuple:
Use set:
Use dict:
list and tupleList → changeable.
Tuple → not changeable.
The duplicate 2 is removed.
None like zerodoes not mean:
It means there is currently no value.
Correct:
Incorrect:
Without quotes, Python treats Sumit as a variable name.
Strings are immutable.
To create a different value:
| Situation | Don't | Do | Reason |
|---|---|---|---|
| Text | name = Sumit | name = "Sumit" | Text needs quotes |
| Changeable collection | Tuple | List | Lists can be modified |
| Fixed collection | List | Tuple | Tuples cannot be changed |
| Unique values | List + manual duplicate removal | Set | Set keeps unique values |
| Structured data | Many separate variables | Dictionary | Key-value structure is easier to manage |
| No value | 0 or "" | None | Clearly represents absence of a value |
| Check type | Guess | type(value) | Python tells you the type |
None?Create a Python program that stores information about a student using different data types.
Use:
int for student IDstr for namefloat for CGPAbool for scholarship statusNone for remarks when there are no remarkstuple for completed semesterslist for current coursesset for unique skillsdict for the complete student profileAdd a new course:
Then print the courses again.
Next, try changing a semester:
You will get a TypeError because tuples are immutable.
This small exercise helps you understand the difference between:
In this lesson, you learned:
int for whole numbersfloat for decimal numbersstr for textbool for True/FalseNone for absence of a valuelist for ordered, changeable collectionstuple for ordered, unchangeable collectionsset for unique valuesdict for key-value datatype()isinstance()In the next lesson, we will continue your Python learning journey with Type Conversion (Casting & type()) (3: Data Types).
👉 Continue to Next Lesson: Type Conversion (Casting & type()) →
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Constants (Python Convention) | Type Conversion (Casting & type()) |
Test your understanding of this lesson with 7 questions. Each question has one correct answer.