Python Data Types

Python supports several built-in data types that are used to store and manipulate data. In this lesson, we will cover some of the most commonly used data types in Python.

Numeric Data Types

  • int: Integer data type, e.g., 5, -3, 0.
  • float: Floating-point data type, e.g., 3.14, -0.001.
  • complex: Complex number data type, e.g., 1+2j, -3-4j.

Text Data Type

  • str: String data type, e.g., "Hello, Python!", '123'.

Sequence Data Types

  • list: Ordered collection of items, e.g. [1, 2, 3], ['a', 'b', 'c'].
  • tuple: Immutable ordered collection of items, e.g., (1, 2, 3), ('a', 'b', 'c').
  • range: Immutable sequence of numbers, e.g., range(5) generates 0, 1, 2, 3, 4.

Mapping Data Type

  • dict: Collection of key-value pairs, e.g., {'name': 'John', 'age': 30}.

Set Data Types

  • set: Unordered collection of unique items, e.g., {1, 2, 3}, {'a', 'b', 'c'}.
  • frozenset: Immutable set, e.g., frozenset({1, 2, 3}).

Boolean Data Type

  • bool: Boolean data type, either True or False.

Conclusion

Understanding the different data types in Python is essential for writing effective and efficient code. By choosing the right data type for your variables, you can ensure that your code is clear, concise, and easy to maintain.



[ Footer Placeholder]