| id | datatype-python | |||
|---|---|---|---|---|
| title | Python Data Types | |||
| sidebar_label | Python Data Types | |||
| sidebar_position | 4 | |||
| tags |
|
|||
| description | Learn all standard data types in Python with examples and explanations. |
In Python, every value has a data type. Data types define the nature of a value, and Python provides a wide variety of built-in data types to handle different kinds of data. Understanding these is crucial for effective programming.
| Category | Data Type |
|---|---|
| Text Type | str |
| Numeric Types | int, float, complex |
| Sequence Types | list, tuple, range |
| Mapping Type | dict |
| Set Types | set, frozenset |
| Boolean Type | bool |
| Binary Types | bytes, bytearray, memoryview |
| None Type | NoneType |
A sequence of Unicode characters.
name = "Dhruba"You can perform operations like:
- Slicing
- Concatenation
- Length check with
len()
Whole numbers:
age = 25Decimal numbers:
pi = 3.14Numbers with real and imaginary parts:
z = 2 + 3jMutable, ordered sequence:
fruits = ["apple", "banana", "cherry"]Immutable, ordered sequence:
dimensions = (1024, 768)Represents a sequence of numbers:
nums = range(5)Unordered collection of key-value pairs:
person = {
"name": "Alice",
"age": 30
}Unordered, mutable, no duplicates:
unique_ids = {1, 2, 3}Immutable version of a set:
readonly_ids = frozenset([1, 2, 3])Only True or False:
is_active = TrueImmutable byte sequence:
b = b"Hello"Mutable version:
ba = bytearray([65, 66, 67])Provides memory-efficient access:
mv = memoryview(bytes([1, 2, 3]))Represents no value:
response = Nonetype(3.14) # Output: <class 'float'>int("5") # Output: 5
str(10) # Output: "10"
list("abc") # Output: ['a', 'b', 'c']Python provides a variety of built-in data types to handle data in efficient and expressive ways. Knowing when and how to use each data type is essential for writing clean and effective Python code.