Python data types

Python offers a variety of built-in data types that allow you to store and manipulate different kinds of data efficiently. Here’s a detailed explanation of some commonly used Python data types along with examples:
1. Numeric Types:
a) int: Represents integer numbers, both positive and negative, without any decimal point.

x = 10
y = -5

b) float: Represents floating-point numbers, which include a decimal point.

pi = 3.14
temperature = -10.5

2. Sequence Types:
a) list: Ordered collection of items, mutable (modifiable).

fruits = ['apple', 'banana', 'orange']
numbers = [1, 2, 3, 4, 5]

b) tuple: Ordered collection of items, immutable (unchangeable).

point = (10, 20)
dimensions = (100, 200, 300)

3. Text Sequence Type:
a) str: Represents strings of characters, enclosed in single (‘ ‘) or double (” “) quotes.

message = 'Hello, World!'
name = "Alice"

4. Mapping Type:
a) dict: Unordered collection of key-value pairs, where each key is associated with a value.

person = {'name': 'John', 'age': 30, 'city': 'New York'}

5. Set Types:
a) set: Unordered collection of unique items.

vowels = {'a', 'e', 'i', 'o', 'u'}

6.Boolean Type:
a) bool: Represents boolean values, either True or False.

is_raining = True
has_apples = False

7. None Type:
a) NoneType: Represents the absence of a value or a null value.

result = None

Let’s look at some examples of using these data types:

# Numeric Types
x = 10
y = 3.14

# Sequence Types
fruits = ['apple', 'banana', 'orange']
point = (10, 20)

# Text Sequence Type
message = 'Hello, World!'
name = "Alice"

# Mapping Type
person = {'name': 'John', 'age': 30, 'city': 'New York'}

# Set Types
vowels = {'a', 'e', 'i', 'o', 'u'}

# Boolean Type
is_raining = True
has_apples = False

# None Type
result = None

These examples demonstrate the usage of various Python data types to store different kinds of data. Understanding these data types and how to use them effectively is essential for writing Python code efficiently and accurately.