Data Type
Data Type
In Python, a data type is a classification that specifies the type of value a variable can hold and what operations can be performed on it. Essentially, it tells the interpreter how to handle the data stored in a variable.
For example:
- Integer (int): Represents whole numbers.
- Float (float): Represents decimal numbers.
- String (str): Represents text.
- Boolean (bool): Represents True or False values.
Here are the basic data types in Python explained in simple terms:
Integer (int): Whole numbers, like
1
,42
, or-7
.Float (float): Decimal numbers, like
3.14
,0.001
, or-2.5
.String (str): Text, enclosed in quotes, like
"hello"
,'world'
, or"123"
.Boolean (bool): True or False values, like
True
orFalse
.List (list): Ordered collection of items, which can be of different types, like
[1, 2, 3]
or["apple", "banana", "cherry"]
.Tuple (tuple): Ordered collection of items, similar to a list, but immutable (cannot be changed), like
(1, 2, 3)
or("apple", "banana", "cherry")
.Set (set): Unordered collection of unique items, like
{1, 2, 3}
or{"apple", "banana", "cherry"}
.Dictionary (dict): Collection of key-value pairs, like
{"name": "Alice", "age": 25}
.
Comments
Post a Comment