Learn Python data types through 100 practical scenarios designed for real-world applications. Start mastering Python today!
No. of downloads:30
1. Python Data Types
Python provides several built-in data types, which are categorized into mutable and immutable types. Understanding these data types is essential for effective Python programming. Here are the main Python data types:
Immutable Data Types (Cannot be changed after creation):
- int: Represents integers, e.g., 5, 100, -3.
- float: Represents floating-point numbers (decimals), e.g., 3.14, -0.001, 2.0.
- str: Represents strings (sequences of characters), e.g., "Hello", "Python".
- tuple: An ordered collection of elements that cannot be changed, e.g., (1, 2, 3), ('a', 'b', 'c').
- frozenset: An immutable version of a set, e.g., frozenset([1, 2, 3]).
Mutable Data Types (Can be changed after creation):
- list: An ordered collection of items that can be changed, e.g., [1, 2, 3], ['a', 'b', 'c'].
- dict: Represents a collection of key-value pairs, e.g., {'name': 'John', 'age': 25}.
- set: An unordered collection of unique elements, e.g., {1, 2, 3}, {'apple', 'banana'}.
- bytearray: A mutable sequence of bytes, e.g., bytearray([65, 66, 67]).