Python Data Type

Python is a dynamically typed language, which means that you don't need to declare the data type of a variable explicitly. The interpreter infers the data type based on the value assigned to it. Python provides several built-in data types for working with different kinds of data. Here are some of the most commonly used data types in Python, along with examples:

1. **Integer (int):**
   - Integers are whole numbers.
   - Example:
 

      
age = 25
      
    

2. **Floating-Point Number (float):**
   - Floats represent real numbers with a decimal point.
   - Example:
 

      
price = 19.99
      
    

3. **String (str):**
   - Strings are sequences of characters enclosed in single, double, or triple quotes.
   - Example:
 

      
name = "John"
      
    

4. **Boolean (bool):**
   - Booleans represent either True or False values.
   - Example:
 

      
is_happy = True
      
    

5. **List:**
   - Lists are ordered collections of items that can be of different data types. They are mutable.
   - Example:
 

      
colors = ["red", "green", "blue"]
      
    

6. **Tuple:**
   - Tuples are similar to lists but are immutable, meaning their elements cannot be changed once defined.
   - Example:
 

      
coordinates = (3, 4)
      
    

7. **Dictionary (dict):**
   - Dictionaries are collections of key-value pairs, where each key is unique.
   - Example:

      
person = {"name": "Alice", "age": 30}
      
    

8. **Set:**
   - Sets are unordered collections of unique items.
   - Example:

      
unique_numbers = {1, 2, 3, 4, 5}
      
    

9. **NoneType (None):**
   - The None data type represents the absence of a value or a null value.
   - Example:

      
result = None
      
    

10. **Custom Classes:**
    - You can define your own custom data types using classes and objects.

      
class Person:
def __init__(self, name, age):
    self.name = name
    self.age = age

# Creating an object of the custom class
person1 = Person("Bob", 28)
      
    

These are the fundamental data types in Python, but Python also supports many other data types and libraries for specialized use cases, such as datetime objects for working with dates and times, NumPy arrays for numerical computations, and more. Understanding and using these data types effectively is crucial for writing Python programs that can manipulate and process data efficiently.