0% found this document useful (0 votes)
6 views12 pages

Day 3 Python Data Types

The document provides an overview of Python data types, explaining their definitions, characteristics, and examples. It categorizes data types into text, numeric, sequence, mapping, set, boolean, and none types, detailing their mutability, order, and allowance for duplicates. Additionally, it emphasizes the importance of data types in preventing errors, improving efficiency, and enhancing code readability.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views12 pages

Day 3 Python Data Types

The document provides an overview of Python data types, explaining their definitions, characteristics, and examples. It categorizes data types into text, numeric, sequence, mapping, set, boolean, and none types, detailing their mutability, order, and allowance for duplicates. Additionally, it emphasizes the importance of data types in preventing errors, improving efficiency, and enhancing code readability.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Day-3

Python - Datatypes
What is a Data Type?

A data type tells Python what kind of information you are storing.

A data type defines the type of value a variable holds and determines
how Python will process, store, and manipulate that value.
Names of Python Data Types

Text Type Numeric Types Sequence Mapping Type


• Str (String) • int, float, Types • dict
complex • list, tuple, range

Set Types Boolean Type None Type


• set, frozenset • bool • None
Text Type: string
“Rohit”

Description: String is used to represent textual data

Type: str

Example: A person's name: “ Rohit ”


Numeric Data type
Type: int

• Description: Stores whole numbers.


• Example: Number of students in a class = 25

Type: float

• Description: Stores decimal numbers.


• Example: Temperature = 37.5 °C

Type: complex

• Description: Number with real + imaginary part


• Example: Electrical circuit calculation, 3 + 4j
Sequence Types: list, tuple, range
Ordered collections of items.

Type: list Type: tuple Type: range

Description: Ordered, Description: Ordered, Description: Sequence of


changeable collection. unchangeable collection. numbers.
Example: Grocery list → Example: Months of the Example: Counting roll
["milk", "bread", "eggs"] year → ("Jan", "Feb", "Mar") numbers → range(1, 51)

Python range(5)

0 1 2 3 4
Mapping Type: dict
Stores data in key–value pairs.
Keys are unique
Value can be any data type

Description: Stores data in Example:


key–value pairs {"name": "John", "age": 20}
• Unordered collections of unique items.
• No duplicate entries
• Order is not guaranteed

Type: set
Set Types:
• Description: Unordered collection of
set, unique items.
frozenset • Example: {"apple", "banana", "orange"}

Type: frozenset

• Description: Same as set, but


unchangeable.
• Example: frozenset(["a", "b", "c"])
Boolean Type: bool
Represents True or False values.

Description: Represents Example: Is the door


True or False values. open? → True / False
None Type: None

Represents no value or empty state.

Example: x= None
Why Data Types Matter

Prevents errors: Efficiency: Correct Readability: Helps


Python knows what type means efficient others understand what
operations are allowed memory usage kind of data is expected

Real-Life Analogy: Like


labeling jars — if you
Debugging: Type errors
label “sugar” but you
are common
put salt, things go
wrong.
Data Type Mutable Ordered Allows Duplicates Example

List Yes Yes Yes ["A", "B"]

Tuple No Yes Yes (1, 2, 3)

{"name":
Dict Yes No Keys unique
"Satish"}

Set Yes No No {1, 2, 3}

Range No Yes Yes range(1,10)

You might also like