Here is a comprehensive list of Python data types along with examples for each:
- int (Integer): Whole numbers
- Example:
x = 10
- Example:
- float (Floating Point): Numbers with decimal points
- Example:
y = 3.14
- Example:
- complex (Complex Numbers): Numbers with real and imaginary parts
- Example:
z = 2 + 3j
- Example:
- list: Ordered, mutable collection
- Example:
fruits = ["apple", "banana", "cherry"]
- Example:
- tuple: Ordered, immutable collection
- Example:
coordinates = (4, 5, 6)
- Example:
- range: Sequence of numbers
- Example:
numbers = range(5)(produces0, 1, 2, 3, 4)
- Example:
- str (String): Sequence of characters
- Example:
greeting = "Hello, World!"
- Example:
- set: Unordered, mutable collection of unique items
- Example:
unique_numbers = {1, 2, 3, 3}(results in{1, 2, 3})
- Example:
- frozenset: Unordered, immutable collection of unique items
- Example:
frozen_set = frozenset([1, 2, 3, 3])(results infrozenset({1, 2, 3}))
- Example:
- dict (Dictionary): Collection of key-value pairs
- Example:
person = {"name": "Alice", "age": 25}
- Example:
- bool: Represents
TrueorFalse- Example:
is_active = True
- Example:
- bytes: Immutable sequence of bytes
- Example:
b = b"hello"
- Example:
- bytearray: Mutable sequence of bytes
- Example:
ba = bytearray(b"hello")
- Example:
- memoryview: Memory view object
- Example:
mv = memoryview(b"hello")
- Example:
- NoneType: Represents a null value
- Example:
x = None
- Example:
- Type Conversion: Python provides functions like
int(),float(),str(), etc., to convert between types.- Example:
x = int("10")converts the string"10"to an integer.
- Example: