Intern
What data types exist in Python?
sobes.tech AI
Answer from AI
In Python, there are built-in and user-defined data types. Built-in types are divided into mutable and immutable types.
Immutable types:
- Numeric types:
int(integers)float(floating-point numbers)complex(complex numbers)
str(strings)tuple(tuples)bytes(byte sequences)frozenset(immutable sets)
Mutable types:
list(lists)dict(dictionaries)set(sets)bytearray(mutable byte sequences)
Other built-in types:
bool(logical type:TrueorFalse)NoneType(type for theNonevalue)
Examples:
# Immutable types
a = 10 # int
b = 3.14 # float
c = "hello" # str
d = (1, 2, 3) # tuple
# Mutable types
e = [1, 2, 3] # list
f = {"a": 1} # dict
g = {1, 2, 3} # set
Brief description:
| Type | Description | Mutable? |
|---|---|---|
int |
Whole numbers | No |
float |
Floating-point numbers | No |
complex |
Complex numbers | No |
str |
Sequence of characters | No |
tuple |
Immutable sequence of elements | No |
bytes |
Immutable sequence of bytes | No |
frozenset |
Immutable unordered set | No |
list |
Mutable sequence of elements | Yes |
dict |
Unordered collection of key-value pairs | Yes |
set |
Mutable unordered set | Yes |
bytearray |
Mutable sequence of bytes | Yes |
bool |
Logical value (True/False) | No |
NoneType |
Type for the None value |
No |
User-defined data types are created by developers using classes.