Data Types in Python
Python has several built-in data types that are used to store different kinds of information.
These data types are classified into several categories: numeric, sequence, mapping, set, and
boolean. Here is a detailed overview of each data type in Python:
1. Numeric Types
Integer ( int ): Whole numbers, positive or negative, without decimals.
age = 30
temperature = -20
Floating-point ( float ): Numbers with a decimal point.
price = 19.99
gravity = 9.8
Complex ( complex ): Numbers with a real and an imaginary part.
complex_number = 1 + 2j
2. Sequence Types
String ( str ): Sequence of characters, enclosed in single or double quotes.
name = "Alice"
greeting = 'Hello, World!'
List ( list ): Ordered, mutable collection of items.
fruits = ["apple", "banana", "cherry"]
numbers = [1, 2, 3, 4, 5]
Tuple ( tuple ): Ordered, immutable collection of items.
coordinates = (10, 20)
colors = ("red", "green", "blue")
Range ( range ): Represents a sequence of numbers.
numbers = range(1, 10)
3. Mapping Type
Dictionary ( dict ): Unordered collection of key-value pairs.
person = {"name": "Alice", "age": 30}
4. Set Types
Set ( set ): Unordered collection of unique items.
unique_numbers = {1, 2, 3, 3, 2}
Python has several built-in data types that are used to store different kinds of information.
These data types are classified into several categories: numeric, sequence, mapping, set, and
boolean. Here is a detailed overview of each data type in Python:
1. Numeric Types
Integer ( int ): Whole numbers, positive or negative, without decimals.
age = 30
temperature = -20
Floating-point ( float ): Numbers with a decimal point.
price = 19.99
gravity = 9.8
Complex ( complex ): Numbers with a real and an imaginary part.
complex_number = 1 + 2j
2. Sequence Types
String ( str ): Sequence of characters, enclosed in single or double quotes.
name = "Alice"
greeting = 'Hello, World!'
List ( list ): Ordered, mutable collection of items.
fruits = ["apple", "banana", "cherry"]
numbers = [1, 2, 3, 4, 5]
Tuple ( tuple ): Ordered, immutable collection of items.
coordinates = (10, 20)
colors = ("red", "green", "blue")
Range ( range ): Represents a sequence of numbers.
numbers = range(1, 10)
3. Mapping Type
Dictionary ( dict ): Unordered collection of key-value pairs.
person = {"name": "Alice", "age": 30}
4. Set Types
Set ( set ): Unordered collection of unique items.
unique_numbers = {1, 2, 3, 3, 2}