Python DataType
python datatype
In Python, data types define the kind of value a variable store, such as numbers, text, or collections.
1. Numeric Data Types
a = 10 # int (Integer)
b = 10.5 # float (Decimal)
c = 3 + 4j # complex (Complex number)
Example:
print(type(a))
print(type(b))
print(type(c))
Output:
<class 'int'>
<class 'float'>
<class 'complex'>
2. String (str)
A string is a sequence of characters.
name = "Ram"
city = 'Mumbai'
print(name)
print(type(name))
Output:-
Ram
<class 'str'>
3. Boolean (bool)
Stores either True or False.
is_student = True
is_working = False
4. List (list)
An ordered, mutable collection. You can add, remove, or change items.
fruits = ["Apple", "Banana", "Mango"]
fruits.append("Orange")
print(fruits)
5. Tuple (tuple)
An ordered, immutable collection. Once created, it cannot be changed.
colors = ("Red", "Green", "Blue")
6. Set (set)
An unordered collection of unique items.
numbers = {1, 2, 3, 4}
7. Dictionary (dict)
Stores data as key-value pairs.
student = {
"name": "Ram",
"age": 25,
"city": "Mumbai"
}
Recommended learning order
Since you're starting Python for data analytics, learn the data types in this order:
-
int -
float -
str -
bool -
list⭐ (most important for NumPy and Pandas) -
tuple -
set -
dict⭐ (very important) -
None
Comments
Post a Comment