Python has several built-in data types. Here’s an overview with examples:
- int: Integer values
- float: Floating-point numbers
- complex: Complex numbers
x = 5 # int
y = 3.14 # float
z = 2 + 3j # complex- Immutable sequences of Unicode characters
- Support slicing, concatenation, and many methods
s = 'hello'
print(s[1:4]) # 'ell'
print(s.upper()) # 'HELLO'- Ordered, mutable sequences
- Allow duplicates and mixed types
lst = [1, 'a', 3.14]
lst.append(42)
print(lst)- Ordered, immutable sequences
- Allow duplicates and mixed types
tpl = (1, 2, 3)
print(tpl[0])- Unordered collections of unique, hashable items
- No duplicates, mutable
s = {1, 2, 3}
s.add(2) # No effect, 2 already present
print(s)- Unordered collections of key-value pairs
- Keys must be unique and hashable
d = {'a': 1, 'b': 2}
d['c'] = 3
print(d)print(type(3.14)) # <class 'float'>
print(isinstance(d, dict)) # Trueprint(int('42')) # 42
print(list('abc')) # ['a', 'b', 'c']